Hdu4800_josephina and RPG (two-dimensional state DP)

Source: Internet
Author: User

///////////////////////////////////////////////////////////////////////////////////////////////////////
tt2767
Disclaimer: This document is subject to the following agreement free reprint-non-commercial-non-derivative-retention Attribution | Creative Commons by-nc-nd 3.0
To view the update and discussion of this article, please click here: http://blog.csdn.net/tt2767
Link is deleted please Baidu: CSDN tt2767
///////////////////////////////////////////////////////////////////////////////////////////////////////

The main puzzle: the status of DP is set to, using the role J to pass the maximum winning probability (Dp[i][j])

From the last start, Count:
DP[I][J] = rate[j][Ai[i]] * MAX (dp[i+1][j], dp[i+1][a[i]);

That is: Use the role J to go through the maximum winning rate of the I-pass = use role J to win the first I-off AI's winning rate * MAX (the probability of the next close with J clearance, the next level of the probability of the AI pass the switch)

Set the initial value, the calendar can be.

#include <sstream>#include <string>#include <iostream>#include <algorithm>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <iterator>#include <vector>#include <map>#include <stack>#include <queue>#include <set>#include <list>#include <functional>#include <numeric>using namespace STD;#define MEM (x, y) memset (x,y,sizeof (×) )inline intLowbit (intx) {returnx& (-X);}typedef  Long Long intLL;Const intINF =0x3f3f3f3f;Const Long DoublePI =ACOs(0.0) *2.0;Const intN =10000+Ten;Const DoubleEPS =1e-6;Doubledp[n][ $],rate[ $][ $];intAi[n];intComb (intXinty);intMain () {intN,m;//ios::sync_with_stdio (FALSE);//close the synchronization stream     while(scanf("%d", &m) = =1)    {intR = Comb (m,3); for(inti =0; I < R; i++) for(intj =0; J < R; J + +)scanf("%LF", &rate[i][j]);scanf("%d", &n); for(inti =0; I < n; i++)scanf("%d", &ai[i]); MEM (DP,0.0); for(intj =0; J < R; J + +) dp[n-1][J] = rate[j][ai[n-1] ]; for(inti = n2; I >=0; i--) { for(intj =0; J < R; J + +) {Dp[i][j] = max (dp[i][j],rate[j][ai[i]] * MAX (dp[i+1][j],dp[i+1[Ai[i]])); }        }Doubleres =0.0; for(intj =0; J < R; J + +) res = max (res,dp[0][J]);printf("%.6lf\n", res); }return 0;}intComb (intXintY) {intu=1, v=1, Len;if(y==0|| X==y)return 1;if(y==1)returnXif(x < y)return 0;if(Y > x/2) y = len = x-y;ElseLen = y; while(len--)        {u*= x--;    V*= y--; }return(int) (u/v);}

Copyright NOTICE: This article for Bo Master original article, allow non-commercial reprint, reprint must note name author (CSDN tt2767) and this blog link: http://blog.csdn.net/tt2767.

Hdu4800_josephina and RPG (two-dimensional 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.