qwq求助
查看原帖
qwq求助
219033
Snow_Dreams楼主2020/5/4 12:00
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 10005;
int depth, n, ans;
struct node{
    int time;
    int life;
    int height;
}a[N];
int f[N][N];
bool cmp(node x, node y){return x.time < y.time;}
signed main()
{
    f[0][0] = 10;
    scanf("%d%d",&depth, &n);
    for(int i = 1;i <= n;i++){
        scanf("%d%d%d",&a[i].time, &a[i].life, &a[i].height);
    }
    sort(a+1, a+n+1, cmp);
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= depth;j++){
            if(f[i][j] >= a[i].time){
                if(f[i][j] >= a[i+1].time){
                    int sum = j+a[i].height;
                    if(sum >= depth){
                        printf("%d",a[i+1].time);
                        return 0;
                    }
                    f[i+1][j] = max(f[i+1][j], f[i][j]+a[i+1].life);
                    f[i+1][sum] = max(f[i+1][sum], f[i][j]);
                }
            }
        }
    }
    for(int i = 1;i <= n;i++) ans = max(ans, f[i][0]);
    printf("%d",ans);
    return 0;
}
2020/5/4 12:00
加载中...