2191
多重背包,用三重循环写的
Sample Input
1
8 2
2 100 4
4 100 2
Sample Output
400
//多重背包
//要求最多数量
#include<bits/stdc++.h>
using namespace std;
int p[110],h[110],c[110];
int dp[110];
//const int INF=0x3f3f3f3f;
int main(){
int t;
scanf("%d",&t);
int n,m;
while(t--){
scanf("%d%d",&n,&m);//金额,种类
for(int i=1;i<=m;i++){
scanf("%d%d%d",&p[i],&h[i],&c[i]);//价格,重量,袋数
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++){
for(int k=1;k<=c[i];k++){
for(int j=n;j>=p[i];j--){
dp[j]=max(dp[j],dp[j-p[i]]+h[i]);
}
}
}
printf("%d\n",dp[n]);
}
return 0;
}