3 solutions
-
1
#include<bits/stdc++.h> using namespace std; const int N=205; int f[N]; int v[N],w[N]; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int n,V; cin>>n>>V; for(int i=1;i<=n;i++){ int s; cin>>s; for(int k=1;k<=s;k++){ cin>>v[k]>>w[k]; } for(int j=V;j>=0;j--){ for(int k=1;k<=s;k++){ if(j>=v[k]){ f[j]=max(f[j],f[j-v[k]]+w[k]); } } } } cout<<f[V]; return 0; }
Information
- ID
- 206
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 47
- Accepted
- 18
- Uploaded By