标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 10477 Accepted Submission(s): 4966
#include<stdio.h> #include<string.h> #include<algorithm> #include<queue> using namespace std; #define N 110 int dp[N][N]; int main() { int n,m,k,s,w[N],v[N]; while(scanf("%d %d %d %d",&n,&m,&s,&k)!=EOF) { for(int i=1;i<=s;i++) { scanf("%d %d",&v[i],&w[i]); } memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++) { for(int j=1;j<=k;j++) { for(int t=1;t<=s;t++) { if(i>=w[t]) { dp[i][j]=max(dp[i][j],dp[i-w[t]][j-1]+v[t]); } } } } if(dp[m][k]<n) printf("-1\n"); else { for(int i=m-1;i>=0;i--) { if(dp[i][k]<n) { printf("%d\n",m-i-1); break; } } } } return 0; }
标签:
原文地址:http://www.cnblogs.com/linliu/p/5136967.html