Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,mw,w,i,j,k;
- cin>>n;
- int wi[n+1],vi[n+1];
- for(i=1;i<=n;i++)
- {
- cin>>wi[i]>>vi[i];
- }
- cin>>mw;
- int c[n+1][mw+1];
- for(i=0;i<=n;i++)
- {
- c[i][0]=0;
- }
- for(i=0;i<=mw;i++)
- {
- c[0][i]=0;
- }
- for(i=1;i<=n;i++)
- {
- for(w=1;w<=mw;w++)
- {
- if(wi[i]>w)
- {
- c[i][w]=c[i-1][w];
- }
- else
- {
- c[i][w]=max(c[i-1][w],(c[i-1][w-wi[i]]+vi[i]));
- }
- }
- }
- cout<<"total="<<c[n][mw]<<endl;
- return 0;
- }
- /*
- 4
- 2 3
- 3 4
- 4 5
- 5 6
- 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement