标签:
/* *********************************************** Author :devil Created 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 namespace std; const int inf=0x3f3f3f3f; int dp[10010],v[510],w[510]; int main() { //freopen("in.txt","r",stdin); int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); m-=n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d%d",&w[i],&v[i]); memset(dp,inf,sizeof(dp)); dp[0]=0; for(int i=1;i<=m;i++) { for(int j=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]); else printf("This is impossible.\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/d-e-v-i-l/p/5064913.html