标签:++i money pen system cassert ems algorithm div color
就是背包,用O(n*m)的一维。
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <cstring> #include <map> #include <queue> #include <set> #include <cassert> #include <stack> #include <bitset> #define mkp make_pair using namespace std; const double EPS=1e-8; typedef long long lon; const lon SZ=10030,INF=0x7FFFFFFF,mod=9901; lon dp[SZ],val[SZ]; int main() { std::ios::sync_with_stdio(0); //freopen("d:\\1.txt","r",stdin); lon casenum; //cin>>casenum; //for(lon time=1;time<=casenum;++time) { int n,dst; cin>>n>>dst; for(int i=1;i<=n;++i) { cin>>val[i]; } dp[0]=1; for(int i=1;i<=n;++i) { for(int j=1;j<=dst;++j) { if(j>=val[i])dp[j]+=dp[j-val[i]]; } } //for(int i=1;i<=dst;++i)cout<<dp[i]<<endl; cout<<dp[dst]<<endl; } return 0; }
标签:++i money pen system cassert ems algorithm div color
原文地址:https://www.cnblogs.com/gaudar/p/9826619.html