这题满水的
典型的dp题,可以用来练习01背包模板
资瓷一下自己的博客:洛谷博客 博客园
首先,我们知道,每个间谍都只有用或不用两种情况 (初步推测出用的是01背包)
其次,我们又知道每个间谍的伪装的能力和不能超过m
再者,我们还知道我们只有x元钱
我们于是就推出了状态转移方程:
(f_{j,l} = max(f_{j,l},f_{j-b,l-c}+a)(jin [m,b],lin [x,c]))
#include <iostream>
#include <cstdio>
using namespace std;
int f[1118][1118]= {0};
int max(int a,int b) {
return a>b ? a : b;
}
int main() {
// freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);//XP机不好调试,只好用freopen
int m,n,x;
cin>>n>>m>>x;
for(int i=1;i<=n;i++) {
int a,b,c;
cin>>a>>b>>c;
for(int j=m;j>=b;j--) {
for(int l=x;l>=c;l--) {
f[j][l]=max(f[j][l],f[j-b][l-c]+a);//very import
}
}
}
cout<<f[m][x];
return 0;
}