2013 Changsha Division Field Competition J-Joseph Phina and RPG

Source: Internet
Author: User
J-Joseph Phina and RPG Time limit:2000 ms Memory limit:32768kb 64bit Io format:% I64d & % i64usubmit status practice HDU 4800

Description

A 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 process of structured demo-making or character development.
Recently, Joseph Phina is busy playing a RPG named tx3. in this game, M characters are available to by selected by players. in the whole game, Joseph Phina is 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 are required to be different. at the beginning of the Challenge Game, the players can choose any characters combination as the START Team. then, they will fight with n ai teams one after another. there is a special rule in the Challenge Game: Once the challenger team beat an AI team, they have 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 only change the characters combination to the latest defeated AI team. the challenger team gets vicw.only if they beat all the AI teams.
Joseph Phina is good at statistics, and she writes a table to record the winning rate between all different character combinations. she wants to know the maximum winning probability if she always chooses best strategy in the game. can you help her?

Input

There are multiple test cases. the first line of each test case is an integer m (3 ≤ m ≤ 10), which indicates the number of characters. the following is a matrix T whose size is r × R. R equals to C (M, 3 ). T (I, j) indicates the winning rate of Team I when it is faced with team J. we guarantee that T (I, j) + T (J, I) = 1.0. all winning rates will retain two 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 are the IDS (0-based) of the AI teams. the IDS can be duplicated.

Output

For each test case, please output the maximum winning probability if Joseph ina uses the best strategy in the game. For each answer, an absolute error not 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 the idea was quite simple: DP. Some errors occurred when reading the question at the beginning, and g ++ was thrown into the trap... DP [I] [J] indicates the probability that the J team will win in the I round, then DP [I] [Cp [I-1] is created by Max (DP [I-1] [J] * num [Cp [I-1] [Cp [I]) (I takes all teams) to update. AC code:
#include<iostream>#include<cstdio>#include<cstring>#include<vector>#include<algorithm>#define INF 0x3f3f3f3f#define M(a,b) memset(a,b,sizeof(a))using namespace std;double num[125][125];int cp[10050];double dp[10050][125];double max(double a,double b){    if(a>b)  return a;    else return b;}int main(){    int t;    int r;    while(scanf("%d",&t)==1)    {        int tp = 1;        for(int i = t;i>t-3;i--) tp*=i;        tp/=6;        for(int i = 0;i<tp;i++)            for(int j = 0;j<tp;j++)        {            scanf("%lf",&num[i][j]);        }        scanf("%d",&r);        for(int i = 0;i<r;i++)            scanf("%d",&cp[i]);        for(int i = 0;i<tp;i++) dp[0][i] = num[i][cp[0]];        for(int x = 1;x<r;x++)        {            dp[x][cp[x-1]] = 0;            for(int i = 0;i<tp;i++)            {                dp[x][cp[x-1]] = max(dp[x][cp[x-1]],dp[x-1][i]*num[cp[x-1]][cp[x]]);                if(i!=cp[x-1])                dp[x][i] = dp[x-1][i]*num[i][cp[x]];            }        }        double ans = 0;        for(int i = 0;i<tp;i++)           if(ans<dp[r-1][i]) ans = dp[r-1][i];        printf("%.6f\n",ans);    }    return 0;}

  

2013 Changsha Division Field Competition J-Joseph Phina and RPG

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.