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 <iostream> #include <algorithm> #include <cstring>
using namespace std;
const int N=1010; int n,v,m; int v[N],w[110],m[110];
int dfs(int x,int spV, int spM){ if(x>n) return 0; else{ if(spV>=v[x] && spM>=m[x]){ if(mem[x][spV][spM]) return mem[x][spV][spM]; else{ mem[x][spV][spM]=max(dfs(x+1,spV,spM),dfs(x+1,spV-v[x],spM-m[x])+w[x]); } } else{ return dfs(x+1,spV,spM); } } }
int main(){ cin>>n>>v>>m; for(int i=1;i<=n;i++){ cin>>v[i]>>m[i]>>w[i]; } int res=dfs(1,v,m); cout<<res<<endl; return 0; }
|