标签:des blog io ar os sp java for strong
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 8243 Accepted Submission(s): 3854
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> #include<cstdlib> using namespace std; int n,m,k,s,dp[110][110],a[110],b[110],minn; int main() { while(scanf("%d%d%d%d",&n,&m,&k,&s)!=EOF) { memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(dp,0,sizeof(dp)); for(int i=1;i<=k;i++) scanf("%d%d",&a[i],&b[i]); for(int i=1;i<=k;i++) for(int j=1;j<=s;j++) for(int p=b[i];p<=m;p++) dp[j][p]=max(dp[j][p],dp[j-1][p-b[i]]+a[i]); if(dp[s][m]<n) printf("-1\n"); else { minn=m; for(int i=0;i<=s;i++) for(int j=0;j<=m;j++) if(dp[i][j]>=n&&j<minn) minn=j; printf("%d\n",m-minn); } } return 0; }
标签:des blog io ar os sp java for strong
原文地址:http://www.cnblogs.com/a972290869/p/4099643.html