1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| #include <bits/stdc++.h> #define ll long long #define int long long #define double long double #define N 1005 #define Orz ios::sync_with_stdio(0),cin.tie(0) #define INF 2e18 #define rep(i,l,r) for(int i=l;i<=r;i++) #define rrep(i,l,r) for(int i=l;i<r;i++) #define pii pair<int,int> #define x first #define y second using namespace std;
signed main(){ string s;getline(cin,s); stringstream ss(s); int w[N],v[N],ind=0; while(ss>>w[ind++]); ind--; for(int i=0;i<ind;i++)cin>>v[i]; int c;cin>>c; int dp[c+5]; memset(dp,0,sizeof(dp)); for(int i=0;i<ind;i++){ for(int j=c;j>=w[i];j--){ dp[j] = max(dp[j],dp[j-w[i]]+v[i]); } } cout<<dp[c]<<endl; }
|