http://poj.org/problem?id=1384
Test instructions: Give the empty and full weight of a savings tank
and give the value and weight of the N-type coins.
What is the minimum value of satisfying a jar when it is filled?
Ideas:
If(DP[J]>DP [J-w [i]]+v [i]) DP[j]=DP[J-W[i] ]+v[i];
#include <cstdio>#include<cstring>#include<cmath>#include<iostream>#include<algorithm>using namespacestd;intMain () {inte,f; intn,t; inti,j,k; intinf=1000000000; intv[ +],w[ +]; intdp[10000+ -]; scanf ("%d",&t); while(t--) {scanf ("%d%d",&e,&f); F=f-e; scanf ("%d",&N); for(i=1; i<=n;i++) scanf ("%d%d",&v[i],&W[i]); for(i=1; i<=f;i++) dp[i]=INF; dp[0]=0; for(i=1; i<=n;i++) { for(j=w[i];j<=f;j++) { if(Dp[j]>dp[j-w[i]]+v[i]) dp[j]=dp[j-w[i]]+V[i]; } } if(Dp[f]<inf) printf ("The minimum amount of money in the Piggy-bank is%d.\n", dp[f]); Elseprintf"This is impossible.\n"); } return 0;}
View Code
POJ 1384 Piggy-bank (full backpack)