题目:http://acm.hdu.edu.cn/showproblem.php?pid=2191
#include <iostream> using namespace std; int main(int argc, const char *argv[]) { int T; //freopen("input.txt","r",stdin); while(cin>>T) { while(T--) { int money,type; int dp[124]={0}; memset(dp,0,sizeof(dp)); cin>>money>>type; for(int i=0;i<type;i++) { int price,weight,num; cin>>price>>weight>>num; for(int k=1;k<=num;k++) for(int j= money;j>=price*k;j--) { int t = dp[j-price]+weight; dp[j]=dp[j]>t?dp[j]:t; //printf("%d钱可获得最大容量%d ",j,dp[j]); } } cout<<dp[money]<<endl; } } return 0; }