标签:with sizeof memset else 限制 include std sync AC
#include <iostream> #include <algorithm> #include <cstring> using namespace std; int dp[110][110]; int n,m,k,s; int w[110]; int val[110]; int main () { ios::sync_with_stdio(false); while (cin>>n>>m>>k>>s) { for (int i=1;i<=k;i++) cin>>val[i]>>w[i]; memset (dp,0,sizeof(dp)); for (int i=1;i<=k;i++) for (int j=w[i];j<=m;j++) for (int t=1;t<=s;t++) dp[j][t]=max (dp[j][t],dp[j-w[i]][t-1]+val[i]); int i; for (i=1;i<=m;i++) if (dp[i][s]>=n) break; if (i>m) cout<<"-1\n"; else cout<<m-i<<"\n"; } return 0; }
标签:with sizeof memset else 限制 include std sync AC
原文地址:https://www.cnblogs.com/xidian-mao/p/8987468.html