当前位置: 代码迷 >> 综合 >> 洛谷----P1156 垃圾陷阱
  详细解决方案

洛谷----P1156 垃圾陷阱

热度:68   发布时间:2024-02-24 16:36:58.0

每个人都有崩溃的时候,就看你的抗压能力到底有多强,如果你的抗压能力强,有办法可以支撑到你能面对并且解决这些困难的话,你就没有问题。                                                                          ----喻言

题目描述

卡门――农夫约翰极其珍视的一条Holsteins奶牛――已经落了到“垃圾井”中。“垃圾井”是农夫们扔垃圾的地方,它的深度为D(2 \le D \le 100)D(2≤D≤100)英尺。

卡门想把垃圾堆起来,等到堆得与井同样高时,她就能逃出井外了。另外,卡门可以通过吃一些垃圾来维持自己的生命。

每个垃圾都可以用来吃或堆放,并且堆放垃圾不用花费卡门的时间。

假设卡门预先知道了每个垃圾扔下的时间t(0< t \le 1000)t(0<t≤1000),以及每个垃圾堆放的高度h(1 \le h \le 25h(1≤h≤25)和吃进该垃圾能维持生命的时间f(1 \le f \le 30)f(1≤f≤30),要求出卡门最早能逃出井外的时间,假设卡门当前体内有足够持续1010小时的能量,如果卡门1010小时内没有进食,卡门就将饿死。

输入格式

第一行为22个整数,DD和 G (1 \le G \le 100)G(1≤G≤100),GG为被投入井的垃圾的数量。

第二到第G+1G+1行每行包括33个整数:T (0 < T <= 1000)T(0<T<=1000),表示垃圾被投进井中的时间;F (1 \le F \le 30)F(1≤F≤30),表示该垃圾能维持卡门生命的时间;和 H (1 \le H \le 25)H(1≤H≤25),该垃圾能垫高的高度。

输出格式

如果卡门可以爬出陷阱,输出一个整表示最早什么时候可以爬出;否则输出卡门最长可以存活多长时间。

输入输出样例

输入 #1复制

20 4
5 4 9
9 3 2
12 6 10
13 1 1

输出 #1复制

13

说明/提示

[样例说明]

卡门堆放她收到的第一个垃圾:height=9height=9;

卡门吃掉她收到的第22个垃圾,使她的生命从1010小时延伸到1313小时;

卡门堆放第33个垃圾,height=19height=19;

卡门堆放第44个垃圾,height=20height=20。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <ctime>
#include <cctype>
#include <bitset>
#include <utility>
#include <sstream>
#include <complex>
#include <iomanip>
#include <numeric>
#include<unordered_set>
#include <climits>//INT_maxnn
#define PP pair<ll,int>
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3fll
#define dinf 1000000000000.0
#define PI 3.1415926
//#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
struct node{int t;int h;int l;
}c[110];
int d,g,sj[110],f[110];
bool cmp(node a,node b)
{return a.t<b.t;
}
int main()
{cin>>d>>g;for(int i=1;i<=g;i++)cin>>c[i].t>>c[i].l>>c[i].h;sort(c+1,c+1+g,cmp);f[0]=10;for(int i=1;i<=g;i++)for(int j=d;j>=0;j--)if(f[j]>=c[i].t){if(j+c[i].h>=d){cout<<c[i].t;return 0;}f[j+c[i].h]=max(f[j+c[i].h],f[j]);f[j]+=c[i].l;}cout<<f[0]<<endl;return 0;
}