原题链接
简单01背包,根据题面背景预处理一下w和v数组即可(就算没有药水也可以获得全部失败的经验)
代码:
//https://blog.csdn.net/hesorchen
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define endl "\n"
#define MAX 1000050
#define PI acos(-1.0)
#define ll long long
#define INF 0x3f3f3f3f
#define mod 1000000009
#define lowbit(abc) (abc & (-abc))
ll lose[1005];
ll win[1005];
ll need[1005];
ll dp[1005];
int main()
{
ll n, m;
cin >> n >> m;
for (ll i = 1; i <= n; i++)
cin >> lose[i] >> win[i] >> need[i];
ll sum = 0;
for (ll i = 1; i <= n; i++)
{
win[i] *= 5;
lose[i] *= 5;
win[i] -= lose[i];
sum += lose[i];
}
fill(dp, dp + 1001, sum);
for (ll i = 1; i <= n; i++)
for (ll j = m; j >= 0; j--)
if (j >= need[i])
dp[j] = max(dp[j], dp[j - need[i]] + win[i]);
cout << dp[m] << endl;
return 0;
}