解析:先把必须要装入的总重量减去就是了。
[code]:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;
int n,w,price[105],weight[105],dp[10005];
int main(){
int i,j,cas,T;
scanf("%d",&cas);
for(T = 1;T <= cas;T++){
scanf("%d%d",&n,&w);
int tmp;
for(i = 1;i <= n;i++){
scanf("%d%d%d",&price[i],&tmp,&weight[i]);
w -= tmp*weight[i];
}
printf("Case %d: ",T);
if(w < 0) puts("Impossible");
else{
memset(dp,0,sizeof(dp));
for(i = 1;i <= n;i++){
for(j = weight[i];j <= w;j++)
dp[j] = max(dp[j],dp[j-weight[i]]+price[i]);
}
printf("%d\n",dp[w]);
}
}
return 0;
}