标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11644 Accepted Submission(s): 5510
#include <iostream> #include <string.h> #include <algorithm> using namespace std; const int INF=0x3f3f3f3f; const int MAXN=1005; int w[MAXN],v[MAXN]; int dp[MAXN][MAXN]; int remain,patience,n,s; int main() { while(cin>>remain>>patience>>n>>s) { memset(dp,0,sizeof(dp)); 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<=patience;j++) { for(int z=1;z<=s;z++) { dp[j][z]=max(dp[j-w[i]][z-1]+v[i],dp[j][z]); } } } int res=-1; for(int i=1;i<=patience;i++) { for(int j=1;j<=s;j++) { if(dp[i][j]>=remain)//若所获得的经验值大于所需的经验值则更新 { res=max(patience-i,res); } } } cout<<res<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5643211.html