luogu-p1095 Watchman's escape--separate DP

Source: Internet
Author: User

P1095 Watchman's escape: https://www.luogu.org/problemnew/show/P1095

Test instructions

There is a person to run in a straight line of s length, the initial magic value of M, with 10 mana can run 60 meters in a second, and ordinary run a second 17 meters. You can restore the Mana value of 4 points by keeping still. Ask if you can run out of T-seconds ago.

Ideas:

Separated two times DP, first run out can use acceleration to use the speed of the journey. Compare the values of DP "I" and DP "I-1" +17 for the second time.

#include <algorithm>#include<iterator>#include<iostream>#include<cstring>#include<iomanip>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<bitset>#include<cctype>#include<queue>#include<cmath>#include<list>#include<map>#include<Set>//#include <unordered_map>//#include <unordered_set>//#include <ext/pb_ds/assoc_container.hpp>//#include <ext/pb_ds/hash_policy.hpp>using namespacestd;//#pragma GCC optimize (3)//#pragma COMMENT (linker, "/stack:102400000,102400000")//C + +#defineLson (L, Mid, RT << 1)#defineRson (mid + 1, R, RT << 1 | 1)#defineDebug (x) cerr << #x << "=" << x << "\ n";#definePB Push_back#definePQ Priority_queuetypedefLong Longll;typedef unsignedLong LongUll;typedef pair<ll, LL >Pll;typedef pair<int,int>Pii;typedef pair<int,pii>P3;//priority_queue<int> Q;//This is a big root heap Q//priority_queue<int,vector<int>,greater<int> >q;//This is a little Gan q//__gnu_pbds::cc_hash_table<int,int>ret[11]; //It's a quick hash_map.#defineFi first#defineSe Second//#define Endl ' \ n '#defineOKC Ios::sync_with_stdio (false); Cin.tie (0)#defineFT (A,B,C) for (int a=b; A <= C;++a)//used to press the line#defineREP (I, J, K) for (int i = j; i < K; ++i)//Priority_queue<int, Vector<int>, greater<int> >que;Constll mos = 0X7FFFFFFFLL;//2147483647Constll nmos = 0X80000000LL;//-2147483648Const intINF =0x3f3f3f3f;Constll inff = 0X3F3F3F3F3F3F3F3FLL;// -Const DoublePi=acos (-1.0); template<typename t>inline T read (t&x) {x=0;intf=0;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') f|= (ch=='-'), ch=GetChar ();  while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx=f?-x:x;}/*-----------------------Showtime----------------------*/            Const intMAXN =300009; intdp[maxn],m,s,t;intMain () {CIN>>m>>s>>T;  for(intI=1; i<=t; i++){                if(M >=Ten) {Dp[i]= dp[i-1]+ -; M-=Ten; }                Else{Dp[i]= dp[i-1]; M+=4; }            }             for(intI=1; i<=t; i++) {Dp[i]= Max (Dp[i], dp[i-1]+ -); if(dp[i]>=s) {Puts ("Yes"); printf ("%d\n", i); return 0; }} puts ("No"); printf ("%d\n", dp[t]); return 0;}
P1095

luogu-p1095 Watchman's escape--separate DP

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.