Rokua P1156 Garbage Trap

Source: Internet
Author: User

2016-05-31 09:54:03

Title Link: Rokua P1156 garbage Trap

Main topic:

The cows fall out of the pit, given the depth of the pit and the number of blocks, each block can be feet or eaten to sustain life (initially 10)

If you can come out, to find the earliest cows out of time, if not come out, to find the longest survival time cows

Solution:

Backpack DP

Dp[i] Indicates the maximum height that can be reached at the moment of survival

There are two different transitions for each state

1. Stepping dp[i]+=a[k].h;

2. Eat Dp[i+a[k].f]=max (Dp[i+a[k].f],dp[i]);

Initial: dp[10]=0;

If you die, just stay where you are, eat, and get the most time.

Places to be aware of:

1. Each block DP finish to sweep the results are satisfied, to meet the direct retreat.

2. The upper limit of time starts with Max (A[I].T), because it doesn't make much sense to live longer than the last block's fall time (as well as a stepping foot)

1 //Garbage Traps (rokua no.1156)2 //Backpack DP3#include <stdio.h>4#include <algorithm>5 using namespacestd;6 Const intmaxn=1100;7 Const intmaxm= the;8 intDP[MAXN];9 intd,g;Ten structnode One { A     intt,f,h; - }; - node A[MAXM]; the BOOLComp (node A,node b) - { -     returna.t<b.t; - } + intMain () - { +scanf"%d%d",&d,&G); AFill (dp,dp+maxn,-100000); atdp[Ten]=0; -      for(intI=1; i<=g;i++) -     { -scanf" %d%d%d",&a[i].t,&a[i].f,&a[i].h);  -     } -Sort (A +1, A +1+g,comp); in      for(intI=1; i<=g;i++) -     { to          for(intj=a[g].t;j>=a[i].t;j--) +         { -Dp[j+a[i].f]=max (dp[j+a[i].f],dp[j]); thedp[j]+=a[i].h; *         } $          for(intj=a[g].t+a[i].f;j>=a[i].t;j--)Panax Notoginseng         { -             if(dp[j]>=D) the             { +printf"%d\n", a[i].t); A                 return 0; the             } +         } -     } $     intf=Ten; $      for(intI=1; i<=g&&f>=a[i].t;i++) -     { -f+=a[i].f; the     } -printf"%d\n", F);Wuyi     return 0; the}

Rokua P1156 Garbage Trap

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.