hdu 1114 Piggy-Bank

`dp[j] = min(dp[j],dp[j-w[i]]+v[i]);//表示质量为j的钱币，含有的最小的价值`

```#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 10000000
int dp[10010],w[555],v[555];
int e,f;

int main()
{
//freopen("input.txt","r",stdin);
int t,coinw,n;
cin>>t;
while(t--)
{
cin>>e>>f;
coinw = f-e;
cin>>n;
for(int i=0; i<=coinw; i++)
dp[i] = INF;
dp[0] = 0;
for(int i=0; i<n; i++)
{
cin>>v[i]>>w[i];
}
for(int i=0; i<n; i++)
{
for(int j=w[i]; j<=coinw; j++)
{
dp[j] = min(dp[j],dp[j-w[i]]+v[i]);
}
}
if(dp[coinw] == INF)
printf("This is impossible.\n");
else
printf("The minimum amount of money in the piggy-bank is %d.\n",dp[coinw]);
}
return 0;
}
```

hdu 1114 Piggy-Bank,布布扣,bubuko.com

HDU 1114 Piggy-Bank 猪仔储钱罐（AC代码）完全背包（容量需满，价值最小）

1 #include <iostream> 2 #define MAX 0xfffffff 3 using namespace std; 4 //要求:1.刚好装满 2.总价值最小 5 int value[501]; 6 int weight[501]; 7 int dp[10010]; 8 int min(int a,int b) 9 { 10 return a<b?a:b; 11 } 12 int cal(int v,int n) //空间.种类 13 { 14 int i,j; 1