Test instructions: To a piggy store, known empty piggy tank and the quality of the piggy store with coins. Then gives the quality and value of the n coins. Ask the minimum amount of money in the Piggy store. Solution: Complete backpack. Note to initialize the INF to exactly full, if the result is INF, the output is impossible.
/************************************************author:d evilcreated time:2015/12/21 21:16:56**************** ******************************** */#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<map>#include<Set>#include<vector>#include<cstdio>using namespacestd;Const intinf=0x3f3f3f3f;intdp[10010],v[510],w[510];intMain () {//freopen ("In.txt", "R", stdin); intT; scanf ("%d",&t); while(t--) { intn,m; scanf ("%d%d",&n,&m); M-=N; scanf ("%d",&N); for(intI=0; i<n;i++) scanf ("%d%d",&w[i],&V[i]); memset (Dp,inf,sizeof(DP)); dp[0]=0; for(intI=1; i<=m;i++) { for(intj=0; j<n;j++) { if(I>=v[j]) dp[i]=min (dp[i],dp[i-v[j]]+W[j]); } } if(Dp[m]!=inf) printf ("The minimum amount of money in the Piggy-bank is%d.\n", Dp[m]); Elseprintf"This is impossible.\n"); } return 0;}
HDU1114 Piggy-bank (Full backpack)