标签:des style blog http color os strong io
完全背包的基础题
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> const int INF = 1e7; using namespace std; int dp[1000005],v[600],p[600]; int max(int x,int y) { if(x > y) return x; else return y; } int min(int x,int y) { if(x > y) return y; else return x; } int main() { int T,VM,Vz,n; scanf("%d",&T); while(T--) { scanf("%d%d",&Vz,&VM); scanf("%d",&n); int st = VM - Vz; for(int i = 0;i<=st;i++) dp[i] = INF; dp[0] = 0; for(int i = 1;i<=n;i++) scanf("%d%d",&p[i],&v[i]); for(int i = 1;i<=n;i++) { for(int j = v[i];j<=st;j++) { dp[j] = min(dp[j-v[i]]+p[i],dp[j]); } } if(dp[st]>=INF) puts("This is impossible."); else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[st]); } return 0; }
HDU 1114 Piggy-Bank 完全背包,布布扣,bubuko.com
标签:des style blog http color os strong io
原文地址:http://blog.csdn.net/wjw0130/article/details/38303457