题意:给出经费的最大值n,再给出 种类m和每种的袋数c、价格p、重量h,求能买大米的最大重量
思路:每种物品有一个固定的次数上限。为多重背包问题。转换为01背包来做
#include<iostream>
#include<stdio.h>
using namespace std;
int dp[110];//最大重量
int main(){
int C,n,m;//测试用例,最大经费,大米种类
int p,h,c;//价格,重量,袋数
scanf("%d",&C);
while(C--){
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&m);
int i,j,k;
for(i=0;i<m;i++){
scanf("%d%d%d",&p,&h,&c);
for(j=0;j<c;j++)//多了一层循环,转换为01背包
for(k=n;k>=p;k--){
int tem=dp[k-p]+h;
if(tem>dp[k])
dp[k]=tem;
}
}
printf("%d\n",dp[n]);
}
return 0;
}