[DP] LGTB Play THD (complex state DP)

Source: Internet
Author: User

LGTB Play THD


LGTB recently played a DotA-like game called THD
One day he was guarding a tower, and N soldiers across the street stood in front of the tower from near to far.
Every creep has a certain amount of blood hi, after killing some money GI
Every second, he can attack any of the live creeps, causing P-point damage, if the soldier's blood volume is less than 1 points, the soldier died, he
Get money. He can also not attack any creeps.
Every second after the LGTB attack, the tower will attack a live creep closest to the tower, causing a Q-point damage if the soldier's blood
Less than 1 points, creeps die, LGTB won't get money
Now LGTB wants to know how much money he can get when he chooses the best strategy.
Input
Enter the first line containing 3 integers p, Q, N
Next n rows, each row contains 2 integers hi, gi
The distance between the first creeps and the tower is I
The meaning of the input is shown in the title face
For 20% of data, 1 N 4
For 50% of data, 1 N 20
For 100% of data, p,q, 1 N, 1 Hi, 0 GI 106
Output
The output contains an integer w representing the maximum amount of money LGTB can get

Sample input
20 60 3
80 100
80 200
120 300

Sample output
500

Convert the amount of creeps into "time", with La Tour and L ' Homme to show how many times, attention to deal with the division of the situation!!

Equivalent to the second dimension indicates how many steps can lead La Tour

Pay special attention to handling initialization!!!! Some states do not exist must be sure not to use to not assign the initial value-inf!!!

AC Code:

#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<vector>#include<queue>#include<stack>#include<map>#include<Set>#include<string>#include<iomanip>#include<ctime>#include<climits>#include<cctype>#include<algorithm>#ifdef WIN32#defineAUTO "%i64d"#else#defineAUTO "%lld"#endifusing namespacestd;#defineSmin (x,tmp) X=min ((x), (TMP))#defineSmax (x,tmp) X=max ((x), (TMP))#defineCost (i) soldier[i].cost#defineHomme (i) soldier[i].homme#defineTour (i) soldier[i].tourConst intinf=0x3f3f3f3f;Const intmaxn= the;intmaxhp=1001;intP,q,n;structsoldier{intTour,homme; intHp,cost; InlinevoidRead () {scanf ("%d%d",&hp,&Cost ); Tour= (HP-1) /Q; Homme= (Hp-tour * Q-1)/P +1; }}SOLDIER[MAXN];intf[maxn][ $/ -*maxn<<1];intMain () {Freopen ("thd.in","R", stdin); Freopen ("Thd.out","W", stdout); scanf ("%d%d%d",&p,&q,&N);  for(intI=1; i<=n;i++) Soldier[i].read ();  for(intI=0; i<=n;i++)         for(intj=0;j<=maxhp<<1; j + +) F[i][j]=-inf;//the visiting following, but also the possible to visited!!!f[0][1]=0;//given one chance at first!!     for(intI=1; i<=n;i++)         for(intj=0; j<=maxhp;j++)        {            if(J >= Tour (i) +1) Smax (F[i][j], f[i-1][j-(Tour (i) +1)]); if(J >= Tour (i)-Homme (i)) Smax (F[i][j], f[i-1][j-(Tour (i)-Homme (i))] +Cost (i)); } printf ("%d", *max_element (f[n],f[n]+maxhp+1));//From the 0 !    return 0;}
View Code

[DP] LGTB Play THD (complex state 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.