p1156 solution to a problem (not fully resolved)

Title Description

Carmen - Farmer John cherished from a Holsteinscow - has fallen into the "junk well" in. "Well garbage" is the local farmers garbage disposal, its depth D (2 \ Le D \ Le 100) D ( 2 D 1 0 0 ) feet.

Carmen wants to garbage up, wait until piled high with the same well, she will be able to flee from the well. In addition, Carmen can sustain their lives by eating junk.

Each can be used to refuse to eat or stacked and piled up garbage without spending time Carmen.

Suppose Carmen know in advance each time garbage dropped T (0 <T \ Le 1000) T ( 0 < T . 1 0 0 0 ), and the height of each Dumping of H (. 1 \ Le H \ Le 25 H ( 1 H 2 5) and eat into the garbage can sustain life time f (1 \ Le f \ Le 30) f ( 1 f 3 0 ), requires the Carmen earliest time to escape out of the well, Suppose the current body has sufficient duration Carmen 10 . 1 0 hours of energy, if Carmen 10 . 1 not eaten within 0 hours, Carmen will starve.

Input and output formats

Input formats:

 

The first line 2 two integers, D D, and  G (. 1 \ Le G \ Le 100) G ( . 1 G . 1 0 0 ), G G is the amount of waste being put in the well.

Second to G. 1 + G + . 1 lines each comprising . 3 three integers: T (0 <T <= 1000) T ( 0 < T < = . 1 0 0 0 ), represents a time waste is thrown into the well; F. (. 1 \ Le F. \ Le 30) F. ( . 1 F. . 3 0 ), it indicates that the garbage can maintain time Carmen life; and  H (. 1 \ Le H \ Le 25) H ( . 1 H 2 . 5 ) the garbage can elevate height.

 

Output formats:

 

If Carmen can climb out of the trap, the output of a whole indicate when the earliest climb out; otherwise the output Carmen can survive the longest long.

 

Sample input and output

Input Sample # 1:  Copy
20 4
5 4 9
9 3 2
12 6 10
13 1 1
Output Sample # 1:  Copy
13

If Carmen can climb out of the trap, the output of a whole indicate when the earliest climb out; otherwise the output Carmen can survive the longest long.

 dp real hammer. (Out of the door, and dp bumped, face problems to do with the backpack breath at night, good fresh!)

After a pass cranky, I think the state should be blood. (Indeed proved to be the blood)

Then it seems relatively clear up.

Direct enumeration blood current height. But the equation seems a bit lost ,,,

Enumeration height (i), the enumeration n (j). dp [i] table depending on the current height of the blood.

DP [a mat grass block] = max (dp [dropped to a grass block eat], DP [dropped to eat a grass block, pad])

Draw focus! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !

 

 

dp[i]+=e[i].f;

 

 

 

This is what I did not expect (although hindsight is such a thing)

Pit:

1, the input is not in chronological order, so sorting.

2, when dp [i] = 0, the cow moribund state, initialized to -1

Unresolved issues:

1, j why enumeration to reverse?

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=10005;
int dp[maxn];//i=height;dp[i]=life
int n,m; 
int maxm;
struct node
{
    int t,f,h;
}e[maxn];
bool cmp(node a,node b)
{
    return a.t<b.t;
}
int main ()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&e[i].t,&e[i].f,&e[i].h);
    }
    sort(e+1,e+m+1,cmp);
    memset(dp,-1,sizeof(dp));
    dp[0]=10;
    for(int i=1;i<=m;i++)
    {
        for(int j=n;j>=0;j--)
        {
            if(dp[j]>=e[i].t)
            {
                if(j+e[i].h>=n)
                {
                    printf("%d",e[i].t);
                    return 0;
                }
                dp[j+e[i].h]=max(dp[j],dp[j+e[i].h]);
                dp[j]+=e[i].f;
            }
        }
    }
    //for(int i=1;i<=n;i++)
    printf("%d",dp[0]);
    return 0;
}
 
 

Guess you like

Origin www.cnblogs.com/ajmddzp/p/11026045.html