HDU 4800 Joseph Phina and RPG

Source: Internet
Author: User
Joseph Phina and RPG

Time Limit: 4000/2000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 605 accepted submission (s): 165
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 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?

 

Inputthere 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.

 

Outputfor each test case, please output the maximum winning probability if Joseph uses the best strategy in the game. For each answer, an absolute error not more than 1e-6 is acceptable.

 

Sample input40.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 output0.0000000

 

This question is to give your m ..

Then create a matrix of C (3, m) * C (3, m) and start DP

The main difference is that if one team wins another, it can be used to ban the next game or continue to select the current team.

Then a DP [I] [J]... indicates the maximum probability that the team J will be used to fl to the I-th AI team, and then the transfer starts.

However, writing is poor ~

 

#include <iostream>#include <cstring>#include <algorithm>#include <cstdio>using namespace std;#define eps 1e-6double dp[10010][121] , p[122][122];long long f[12];int x[10010];int n , m ;long long r;void init(){    for( int i = 0 ; i <= n ; ++i ){        for( int j = 0 ; j <= r ; ++j ){                dp[i][j] = 0.0 ;            }        }        for( int i = 0 ; i < r ; ++i ){            dp[1][i] = max ( dp[1][i] ,  p[ i ][ x[1] ] ) ;            dp[1][ x[1] ] = max( dp[1][ x[1] ] , dp[1][i] );        }}int main(){    ios::sync_with_stdio(0);    f[0] = 1;    for( int i = 1 ; i < 11 ; ++i ){ f[i] = i * f[i-1] ; }//    freopen("in","r",stdin);    while( ~scanf("%d",&m) ){        r = f[m] /  f[3] / f[m-3] ;        for( int i = 0 ; i < r ; ++i ){            for( int j = 0 ; j < r ;++j ){                scanf("%lf",&p[i][j]) ;            }        }        scanf("%d",&n );        for( int i = 1 ; i <= n ;++i ){            scanf("%d",&x[i]);        }        init();        for(int i = 2 ; i <= n  ; ++i ){            for( int j = 0 ; j < r ; ++j ){                dp[ i ] [ x[i] ]= max( dp[ i ][ x[i] ] , dp[ i - 1 ][ j ] * p[ j ][ x[i] ]  );                dp[ i ] [ j ] = max ( dp[ i ][ j ] , dp[ i - 1 ][ j ] * p[ j ][ x[i] ]  );            }        }        double ans = 0.0 ;        for( int j = 0; j < r ; ++j ){            ans = max( ans , dp[n][j] );        }        printf("%.6lf\n", ans );    }    return 0;}

 

HDU 4800 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.