1684 Garbage traps

Source: Internet
Author: User

1684 Garbage traps

time limit: 1 sspace limit: 128000 KBtitle level: Golden Gold SolvingTitle Description Description

Carmen--a holsteins cow that farmer John Cherished dearly--has fallen into the "trash well." "Trash Well" is where farmers throw rubbish, with a depth of D (2 <= d <= 100) feet.

Carmen tried to pile up the rubbish, and when the heap was as high as the well, she could escape out of the well. In addition, Carmen can maintain her life by eating some rubbish.

Every litter can be used to eat or stack, and to pile up rubbish does not take Carmen's time.

Suppose Carmen knew in advance what time t (0<t<=1000) each garbage dropped, and the height of each garbage heap H (1<=h<=25) and the time F (1<=f<=30) to eat the garbage to sustain life, Ask Carmen to escape the first time outside the well, assuming that Carmen currently has enough energy to last 10 hours, if Carmen did not eat within 10 hours, Carmen will starve to death.

Enter a description Input Description

The first Acts 2 integers, D and g (1 <= g <=), G for the amount of garbage put into the well.

The second to the G+1 line consists of 3 integers: T (0 < T <= 1000), indicating the time that the garbage was dropped into the Well, F (1 <= F <= 30), indicating that the garbage could maintain the time of Carmen's life, and H (1 <= H <= 25), the garbage can Height to be padded.

Output description Output Description

If Carmen can crawl out of the trap, output an integer indicating when the earliest can be crawled out, or how long the output of Carmen can survive.

Sample input Sample Input

20 4

5 4 9

9 3 2

12 6 10

13 1 1

Sample output Sample Output

13

Data range and Tips Data Size & Hint

[Sample Description]

Carmen piled up the first rubbish she received: height=9;

Carmen eats the second litter she receives, extending her life from 10 hours to 13 hours;

Carmen piled up a 3rd litter, height=19;

Carmen piled up a 4th litter, height=20.

Category labels Tags Click here to expandNo label AC code + Explanation:
/*first, according to the time of garbage disposal; F[i] indicates that the heap of garbage height is the longest time to live in Carmen, and each time the judging condition is whether the time to survive is greater than the time of the garbage, if not Carmen will starve to death, and the height of the rubbish is no greater than or equal to the height of the trap, if yes Can crawl out, treat every garbage, eat or heap, then there are two formulas: F[j+a[i].h]=max (F[j+a[i].h],f[j]),//heap f[j]+=a[i].f;//eat if not climb out, then the longest time to survive is f[0], that is, the All the rubbish was eaten;*/#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<algorithm>using namespacestd;Const intn=1001;structnode{intT,f,h;} A[n];intD,g,f[n];BOOLSi=1;BOOLcmpConstNode &x,ConstNode &b) {    returnx.t<b.t;}intMain () {scanf ("%d%d",&d,&g);  for(intI=1; i<=g;i++) scanf ("%d%d%d",&a[i].t,&a[i].f,&a[i].h); Sort (a+1, a+g+1, CMP); f[0]=Ten;  for(intI=1; i<=g;i++){         for(intj=d;j>=0; j--){            if(f[j]>=a[i].t) {                if(J+a[i].h>=d) {printf ("%d", a[i].t);return 0;} F[j+a[i].h]=max (F[j+a[i].h],f[j]);//Don't eatF[J]=F[J]+A[I].F;//Eat}}} printf ("%d", f[0]); return 0;}

1684 Garbage traps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.