Piggy-Bank HDU - 1114 完全背包
作者:互联网
#include<iostream> #include<cstring> using namespace std; const int INF=0x3f3f3f3f; int t,e,f,n,dp[10010]; struct node { int p, w; //价值 重量 } no[10000]; int main() { cin >> t; while(t--) { memset(dp,0x3f,sizeof dp); //e是空存钱罐的重量,f是满存钱罐的重量,n是钱的种数。 cin>>e>>f>>n; for(int i = 0; i < n; i++) cin>>no[i].p>>no[i].w; dp[0]=0; for(int i=0;i<n;i++) for(int j=no[i].w;j<=f-e;j++) dp[j]=min(dp[j],dp[j-no[i].w]+no[i].p); if(dp[f - e]!=INF) cout << "The minimum amount of money in the piggy-bank is " << dp[f - e] << "." << endl; else cout << "This is impossible." << endl; } return 0; }
标签:HDU,Bank,int,no,cin,Piggy,存钱罐,include,dp 来源: https://www.cnblogs.com/QingyuYYYYY/p/12238244.html