Zoj 3735 Probability DP

Source: Internet
Author: User

Josephina and RPG Time limit: 2 Seconds Memory Limit: 65536 KB Special Judge

A role-playing game (RPG and sometimes roleplaying game) is a game in which players assume the roles of characters in a fi Ctional 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  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 get 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?

Input

There 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 R is x. R R equals to C ( M , 3). Indicates the T(i, j) winning of team when i it was 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.

Output

For 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
4 0.50 0.50 0.20 0.30 0.50 0.50 0.90 0.40 0.80 0.10 0.50 0.60 0.70 0.60 0.40 0.50 3 0 1 2
Sample Output
0.378000

Topic Links: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3735

Idea: Set Dp[i][j] to play "The first enemy with the first J of the maximum winning percentage of the team", then the state transfer there are two, set P[x][y] for the first team of the X-y team, set the first AI is the team K. Then we have:
For (J:1-m) dp[0][j] = 1.0;
for (I:1-N)
For (J:1-M)
DP[I][J]=P[J][K] * MAX (dp[i+1][j],dp[i+1][k]);
The first means not to change, the second is to change the type. The maximum value for the last for Loop Dp[1][j].

AC Code:

1#include <iostream>
2#include <cstdio>
3#include <cstring>
4usingnamespaceStd
5intM, N;
6intai[10010];
7Doublebeat[ Max][ Max], dp[10010][ Max];
8intMain () {
9 while(~SCANF ("%d", &m)) {
Tenmemset (AI,0,sizeof(AI));
OneMemset (DP,0.0,sizeof(DP));
Am = m * (M-1) * (M-2) /6;
- for(inti =0; I < m; i++) {
- for(intj =0; J < M; J + +) {
thescanf"%LF", &beat[i][j]);
-}
-}
-scanf"%d", &n);
+ for(inti = n; i >0; i--)
-scanf"%d", &ai[i]);
+ for(inti =0; I < Max; i++) {
Adp[0][i] =1.0;
at}
- for(inti =1; I <= N; i++) {
- for(intj =0; J < M; J + +) {
- if(Dp[i-1][J] > Dp[i-1][ai[i]])
-DP[I][J] = beat[j][ai[i]] * dp[i-1][J];
-Else
inDP[I][J] = beat[j][ai[i]] * dp[i-1][ai[i]];
-}
to}
+DoubleAns =-1.0;
- for(inti =0; I < m; i++) {
theif(Ans < dp[n][i])
*ans = dp[n][i];
$}
Panax Notoginsengprintf"%lf\n", ans);
-}
thereturn0;

+  }

Zoj 3735 Probability 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.