Football
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 3145 |
|
Accepted: 1591 |
Description
Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, ..., 2n. In each round of the tournament, all teams still in the tournament is placed in a list in order of increasing index. Then, the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers is eliminated. After n rounds, only one team remains undefeated; This team is declared the winner.
Given a matrix P = [Pij] such that pij are the probability that team I 'll beat Team C7>j in a match determine which team are most likely to win the tournament.
Input
The input test file would contain multiple test cases. Each test case would begin with a single line containing n (1≤ n ≤7). The next 2n lines each contain 2n values; Here, theJ-th value on the i-th line represents pij. The Matrix P would satisfy the constraints that pij = 1.0? Pji for all i ≠ J, and pii = 0.0 for all i. The end-of-file is denoted by a single line containing the number? 1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure so use either the double
data type instead of float
.
Output
The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it's guaranteed, the difference in win probability for the top of the teams 'll is at least 0.01.
Sample Input
20.0 0.1 0.2 0.30.9 0.0 0.4 0.50.8 0.6 0.0 0.60.7 0.5 0.4 0.0-1
Sample Output
2
Probability DP.
Test instructions: Football knockout. A co-owned N round, together with the 2^n team to participate in the game, so a total of N-round game can be the winner. Set DP[I][J] is the probability that J team wins in the first round of the race. Then dp[i][j]=dp[i-1][j]*dp[i-1][k]*p[j][k].k for the opponent in this round J.
Then the following question is how to find out K. Be able to list the race process in 2 binary state. And then be able to find patterns:j>>i-1^1==k>>i-1;
#include <iostream> #include <cmath> #include <cstdio> #include <cstring>using namespace std;# Define ll Long longdouble Dp[8][130],p[130][130];int main () { int n; while (scanf ("%d", &n)!=eof&&n!=-1) { int num=1<<n; Memset (Dp,0,sizeof (DP)); for (int. i=0;i<num;i++) {for (int j=0;j<num;j++) scanf ("%lf", &p[i][j]); Dp[0][i]=1;} for (int i=1;i<=n;i++) for (int j=0;j<num;j++) for (int k=0;k<num;k++) { if (j>> (i-1) ^1) = = (k >>i-1)) dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k]; } int ans;double max=-1;for (int i=0;i<num;i++) {if (Dp[n][i]>max) {ans=i+1; Max=dp[n][i];}} printf ("%d\n", ans); } return 0;}
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
POJ 3071-football (possibility DP)