"POJ3071" Football-state compression + expected DP

Source: Internet
Author: User

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 C4>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, the J-th value on the i-th line represents pij. The Matrix P would satisfy the constraints that pij = 1.0− pji for all ij, 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.

Main topic

For you to $2^n$ a team, must be adjacent to the team to be able to play, telling you I team to win the J team probability, ask which team to win the most probability.

Ideas

Set $f_{i,j}$ to indicate the probability of $j$ winning of the $i$ tournament, enumerating the $k$ of the $j$ tournament, $f_{i,j} = \sum_{k=1}^{2^n}f_{i-1,j}*f_{i-1,k}*p_{j,k}*[$ $\text{ J and K adjacent}]$

Judge adjacent << (I1) and then use the XOR (^) operation to determine

/*************************************************author:lrj124*created Tim E:2018.09.30.19:13*mail: [email protected]*problem:poj3071*********************************** /#include <iostream> #include <cstring> #include <cstdio>using namespace Std;const int MAXN = (1<<7) + 10;double p[maxn][maxn],f[maxn][maxn];int n;int main () {while (CIN >> N) {if (n = =-1) break;m Emset (F,0,sizeof (f)); for (int i = 1;i <= (1<<n); i++) {F[0][i] = 1;for (int j = 1;j <= (1<<n); j + +) scanf ( "%lf", &p[i][j]);}  for (int i = 1;i <= (1<<n), i++) for (int j = 1;j <= (1<<n); j + +) for (int k = 1;k <= (1<<n); k++) if ((((j-1) >> (i-1)) ^1) = = ((k-1) >> (i-1)) f[i][j] + = f[i-1][j]*f[i-1][k]*p[j][k];d ouble Max = 0;int ans;for ( int i = 1;i <= (1<<n); i++) if (F[n][i] > max) {Max = F[n][i];ans = i;} printf ("%d\n", ans);} return 0;} 

"POJ3071" Football-state compression + expected 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.