#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
typedef vector<int> VI;
const int mod = 1e8;
int n,m;
int d;
int t[2010];
int f[1010];
int h[250001];
int dp[101][101];
//枚举余数
vector< int > q[100];
/*
*每一个垃圾要么吃要么堆
*状态有三个 n个垃圾 高度 血
* 第n个垃圾 高度为 h 血为x;
* 这个垃圾投放的先后怎么解决呢
* 按时间排序
*最早排出的时间应该是某一个垃圾扔进来的时间
* 如果排不出去,就把垃圾全吃了
* 垃圾能不能吃到,俩次垃圾的间隔时间和生命值作比较
* */
struct bin{
int t,f,h;
bool operator < (const bin &u)const{
return t < u.t;
}
}g[101];
int main(){
cin>>d>>n;
for(int i=1;i<=n;i++){
cin>>g[i].t>>g[i].f>>g[i].h;
}
sort(g+1,g+1+n);
g[0] ={0,0,0};
memset(dp,-0x3f,sizeof dp);
dp[0][0] = 10;
int res = 10;
for(int i=1;i<=n;i++){
int td = g[i].t - g[i-1].t;
for(int j=d;j>=0;j--){
if(dp[i-1][j] >= td){
if(j + g[i].h >= d){
cout<<g[i].t;
return 0 ;
}
dp[i][j+g[i].h] = max(dp[i][j+g[i].h] ,dp[i-1][j] - td);
dp[i][j] = max(dp[i][j] , dp[i-1][j] + g[i].f - td);
}
}
res = max(res,dp[i][0] + g[i].t);
}
cout<<res;
}
推dp的时候也可以从 当前状态 能够 转移到什么状态来考虑,不一定非要从 当前状态能够由什么状态来考虑
dp方程基本是我推出来的,有的小问题没考虑到,
就是如果剩余的时间 不够支撑到下一次垃圾时间的到来,那么后续的所有都不会跟新
因为每个垃圾更新完 都要跟新一次答案 res = max(res,dp[i][0] + g[i].t)