Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main ()
- {
- int profit[100][100], wt[100], value[100];
- int n, W;
- cin >> n;
- for(int i = 0; i < n; i++) cin >> value[i] >> wt[i];
- cin >> W;
- for(int i = 0; i <= n; i++) {
- for(int j = 0; j <= W; j++) {
- if(i == 0 || j == 0) profit[i][j] = 0;
- else if(j >= wt[i-1]) {
- profit[i][j] = max(profit[i-1][j], value[i-1]+profit[i-1][j-wt[i-1]]);
- }
- else {
- profit[i][j] = profit[i-1][j];
- }
- }
- }
- cout << profit[n][W];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement