Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int W;
- int size=0;
- int a[300];
- int mem[300][10000];
- int f(int i, int w){
- if (i == size){
- return w;
- }
- if (mem[i][w]){
- return mem[i][w];
- }
- if (w+a[i] > W)
- return mem[i][w] = f(i+1, w);
- return mem[i][w] = max(f(i+1, w+a[i]), f(i+1, w));
- }
- int main(){
- cin >> W;
- while (cin>>a[size]) size++;
- cout << f(0,0) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement