P1095 Rye fled --DP? greedy?

https://www.luogu.org/problem/P1095

Demon Hunter Illidan ambitious, he betrayed the night elves, led deep in the seabed of Naga attempted mutiny. Rye suffered a clash with Dian Wei Sha's trapped in a large barren island. In order to kill the Rye, Dian began to cast a spell on this island, the island will soon sink.

By that time, everyone will be killed on the island. Rye running speed of 17m / s, at such a speed that can not escape the desert island. Fortunately Rye has flashes of magic, can move within 60m 1s, but each time flashing spells consume mana 10:00. Magic value Rye recovery speed of 4:00 / s,

Only in place in order to restore the resting state.

Rye magic now known initial value M, the distance between the initial position and exit the island where he S, island sinking time T. Your task is to write a program to help figure out how to escape from a desert island Catcher in the shortest possible time, if not escape, the output Catcher in the remaining time can go the farthest distance.

Note: Rye running, flicker or break activities are seconds (s) as a unit, and the duration of each activity is an integer seconds. Unit distance in meters (m).

 

A total line, comprising three non-negative integers separated by spaces M, S, T.

 

Output formats
total of two lines.

The first acts of the string "Yes" or "No" (case sensitive), namely whether Rye flee the island.

The second row contains an integer. The first line represents the Rye island to escape the shortest time when "Yes" (case-sensitive); The first line "No" represents the Rye can go the farthest distance when (case-sensitive).

 

This question has a little bar DP and greedy, thought to be several dimensions, but one-dimensional enough;

We want to know the quickest escape, you can use magic with magic, this is the best, but we need to consider whether to stay or return more magic about dying;

 

We use DP [i] i can go as far as time is how much of the road,

We divide the processing magic walk, first deal only with magic, walk in processing;

We can choose to go walking or the use of magic, taking the maximum on the line;

Because the reply magic and no time limit, use magic with magic must be optimal;

We changed only the second is to walk or use magic, did not change one second ago;

#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=3e5+10;
int m,s,t;
int dp[maxn];
int main()
{
    scanf("%d%d%d",&m,&s,&t);
    for(int i=1;i<=t;i++)
    {
        if(m>=10) 
        {
            dp[i]=dp[i-1]+60;
            m-=10;
        }
        else 
        {
            dp[i]=dp[i-1];
            m+=4;
        }
    }
    for(int i=1;i<=t;i++)
    {
        dp[i]=max(dp[i-1]+17,dp[i]);
        if(dp[i]>=s)
        {
            printf("Yes\n%d",i);
            return 0;
        }
    }
    printf("No\n%d",dp[t]);
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/WHFF521/p/11593511.html