P1802 5 倍经验日

链接:https://www.luogu.com.cn/problem/P1802
额,dp的板子?差不多,就加一个变式就行(
代码:

#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;

const int N = 1e3 + 5;
ll n, x;
struct peo
{
	ll lose, win, use;
}people[N];
ll dp[N][N];
ll dfs(ll i, ll j)
{
	//前i个物品进入j的背包
	if (dp[i][j] != 0)return dp[i][j];
	if (i == 0)return 0;
	ll res;
	if (j >= people[i].use)res = max(dfs(i - 1,j - people[i].use )+ people[i].win, dfs(i - 1,j)+people[i].lose);
	else res = dfs(i - 1, j) + people[i].lose; // 这里不能忘
	return dp[i][j] = res;//这种写法好爽(
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n >> x;
	for (int i = 1; i < 1 + n; i++)//切记按1开始存
	{
		cin >> people[i].lose >> people[i].win >> people[i].use;
	}
	cout << dfs(n, x) * 5;
	return 0;
}

posted on 2024-04-03 21:42  WHUStar  阅读(1)  评论(0编辑  收藏  举报