标签:acm sam without input pac ros cas with only
Description
Input
Output
Sample Input
3
10 110
2
1 1
30 50
10 110
2
1 1
50 30
1 6
2
10 3
20 4
Sample Output
The minimum amount of money in the piggy-bank is 60.
The minimum amount of money in the piggy-bank is 100.
This is impossible.
题解
完全背包(恰与不超过的初始化不同)
1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 #define maxn 505 5 #define inf 1<<29 6 #define maxm 10005 7 using namespace std; 8 int T,m1,m2,m,n; 9 int dp[maxm],v[maxn],val[maxn]; 10 int main() 11 { 12 scanf("%d",&T); 13 while(T--) 14 { 15 scanf("%d%d",&m1,&m2); 16 m=m2-m1; 17 scanf("%d",&n); 18 for(int i=1 ; i<=n ; ++i) 19 scanf("%d%d",&val[i],&v[i]); 20 for(int i=1 ; i<=m ; ++i)dp[i]=inf; 21 dp[0]=0; 22 for(int i=1 ; i<=n ; ++i) 23 for(int j=v[i] ; j<=m ; ++j) 24 dp[j]=min(dp[j],dp[j-v[i]]+val[i]); 25 if(dp[m]==inf)printf("This is impossible.\n"); 26 else printf("The minimum amount of money in the piggy-bank is %d.\n",dp[m]); 27 } 28 return 0; 29 }
标签:acm sam without input pac ros cas with only
原文地址:http://www.cnblogs.com/fujudge/p/7523063.html