HDU 4800 Josephina and RPG (Dynamic planning)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4800


Surface:

Josephina and RPG Time limit:4000/2000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1077 Accepted Submission (s): 320
Special Judge


Problem Descriptiona role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of Characters in a fictional setting. Players take responsibility for acting out these roles within a narrative, either through literal acting or through a proc ESS of structured decision-making or character development.
Recently, Josephina is busy playing a RPG named TX3. In this game, M characters is available to by selected by players. In the whole game, Josephina are most interested in the ' Challenge game ' part.
The challenge game is a team play game. A Challenger team is made up of three players, and the three characters used by players in the team was required to be dif Ferent. At the beginning of the challenge Game, the players can choose any characters combination as the start team. Then, they'll fight with the N AI teams one after another. There is a special rule in the challenge game:once the Challenger team beat an AI team, they has a chance to change the Current characters combination with the AI team. Anyway, the Challenger team can insist on using the current team and ignore the exchange opportunity. Note that the players can is only a change of the characters combination to the latest defeated AI team. The Challenger team gets victory only if they beat all the AI teams.
Josephina is good at statistics, and she writes a table to record the winning rate between all different character Combina tions. She wants to know the maximum winning probability if she is always chooses best strategy in the game. Can you help her?

Inputthere is multiple test cases. The first line of all test case was an integer M (3≤m≤10), which indicates the number of characters. The following is a matrix T whose size was rxr. R equals to C (M, 3). T (i, J) indicates the winning rate of team I when it's faced with Team J. We guarantee that T (I, J) + T (j, i) = 1.0. All winning rates would retain the other decimal places. An integer N (1≤n≤10000) is given next, which indicates the number of AI teams. The following line contains N integers which is the IDs (0-based) of the AI teams. The IDs can be duplicated.
Outputfor Each test case, please output the maximum winning probability if Josephina uses the best strategy in the game. For each answer, the an absolute error isn't more than 1e-6 is acceptable.

Sample Input
40.50 0.50 0.20 0.300.50 0.50 0.90 0.400.80 0.10 0.50 0.600.70 0.60 0.40 0.5030 1 2

Sample Output
0.378000

Source2013 Asia Changsha Regional Contest

Solving:
Every three people form a team, so the size of R is C (3,n). The given array is a combination of some combinations that match the odds of winning. You can choose a combination at the beginning. DP[I][J] stands for, I this position currently chooses J This combination the success rate. Pushing from the regular i-1 to I seems hard to push, because I don't know what was used before or whether it was replaced before. At this point the conversion is going to be pushed from I to i+1.
DP[I+1][J]=Max(DP[I+1][J],DP[I][J]*Rate[J][Rival[I+1]]);DP[I+1][Rival[I]]=Max(DP[I+1][Rival[I]],DP[I][J]*Rate[Rival[I]][Rival[I+1]]);
The value of Dp[i+1][j] in the next position is the maximum value of its original value, and the success rate at which J is maintained at the i+1 position.
The value of Dp[i+1][rival[i]] in the next position is the maximum value of its original value, and the success rate of the opponent in the i+1 position with the previous round defeated.
The answer is to traverse the last position to fetch the largest of all the combinations.

Code:
 #include <iostream> #include <cstring> #include <cstdio> #include < Cstdlib>using namespace std;double rate[260][260],dp[10010][260],ans;int rival[10010];d ouble max (double a,double b ) {return a>b?a:b;} int C (int a,int b) {int res=1;for (int i=1;i<=a;i++) res=res* (b-i+1)/i;return Res;}  int main () {int n,t;while (scanf ("%d", &n)!=eof) {n=c (3,n);      ans=0.0;      for (int. i=0;i<n;i++) for (int j=0;j<n;j++) scanf ("%lf", &rate[i][j]);  scanf ("%d", &t);  for (int i=0;i<t;i++) scanf ("%d", &rival[i]);      for (int i=0;i<t;i++) for (int j=0;j<n;j++) dp[i][j]=0.0;  for (int i=0;i<n;i++) dp[0][i]=rate[i][rival[0]];  for (int i=0;i<t-1;i++) {for (int j=0;j<n;j++) {Dp[i+1][j]=max (dp[i+1][j],dp[i][j]*rate[j][rival[i+1]]);  Dp[i+1][rival[i]]=max (dp[i+1][rival[i]],dp[i][j]*rate[rival[i]][rival[i+1]);  }} for (int i=0;i<n;i++) Ans=max (Ans,dp[t-1][i]); printf ("%.6lf\n", ans);} return 0;} 



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 4800 Josephina and RPG (Dynamic planning)

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.