标签:表示 data- color while 多重背包 int sizeof iostream mem
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 26954 | Accepted: 9533 |
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int main() { int cash,num,i,j; int n[15]; int w[15]; int dp[10001]; int count[10001]; while(cin>>cash>>num) { for(i=0;i<num;i++) cin>>n[i]>>w[i]; memset(dp,0,sizeof dp); for(i=0;i<num;i++) { memset(count,0,sizeof count); for(j=w[i];j<=cash;j++) if(dp[j]<dp[j-w[i]]+w[i]&&count[j-w[i]]<n[i]) { dp[j]=dp[j-w[i]]+w[i]; count[j]=count[j-w[i]]+1; } } cout<<dp[cash]<<endl; } return 0; }
标签:表示 data- color while 多重背包 int sizeof iostream mem
原文地址:http://www.cnblogs.com/yangykaifa/p/7068162.html