-
时间:2016-03-27 16:37:56 星期日
-
题目编号:[2016-03-27][HDU][1114][Piggy-Bank]
-
遇到的问题:注意f == e的情况,即dp[0] = 0;
#include <cstring>
#include <cstdio>
#include<algorithm>
using namespace std;
int dp[10000 + 10];
int w[500 + 10],c[500 + 10];
int main(){
int t;
scanf("%d",&t);
while(t--){
int e,f,n;
scanf("%d%d%d",&e,&f,&n);
for(int i = 0;i < n;++i){
scanf("%d%d",&w[i],&c[i]);
}
memset(dp,0x7f,sizeof(dp));
dp[0] = 0;
for(int i = 0;i < n;++i){
for(int v = c[i];v <= f - e;++v){
dp[v] = min(dp[v] , dp[v - c[i]] + w[i]);
}
}
if(dp[f - e] == 0x7f7f7f7f) puts("This is impossible.");
else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[f - e]);
}
return 0;
}
时间: 2024-10-20 01:07:47