POJ3071 (Football)

Source: Internet
Author: User

Football
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3469 Accepted: 1782

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.

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

Hint

In the ' test case ' above, teams 1 and 2 and teams 3 and 4 play against each and the first round; The winners of each match then play to determine the winner of the tournament. The probability that Team 2 wins the tournament in this case is:

P (2 wins) = p(2 Beats 1)p(3 beats 4)p(2 beats 3) + p(2 Beats 1)p(4 beats 3)p(2 Beats 4)
= p+p +p p 24
= 0.9 · 0.6 · 0.4 + 0.9 · 0.4 · 0.5 = 0.396.

The next most likely team to win are Team 3, with a 0.372 probability of winning the tournament.

Source

Stanford Local 2006 Probability DP (simple probability of finding)
#include <cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#defineN 130#define_cle (M, a) memset (M, A, sizeof (m))#defineRepu (I, A, b) for (int i = A; I < b; i++)using namespacestd;#defineMAXN 2#defineLL DoubleDoubleP[n][n], win[Ten][n];intMain () {intN;  while(~SCANF ("%d", &n) && n! =-1)    {         for(inti =1; I <= (1<< N); i++)             for(intj =1; J <= (1<< N); J + +) scanf ("%LF", &P[i][j]);  for(inti =1; I <= (1<< N); i++) win[0][i] =1.0; DoubleT;  for(inti =1; I <= N; i++)             for(intj =1; J <= (1<< N); J + +) {               intK = (J-1) / (1<< (I-1)); T=0.0; ifK2)                   for(intQ = (K-1) * (1<< (I-1)) +1; Q <= k * (1<< (I-1)); q++) T+ = Win[i-1][J] * Win[i-1][Q] *P[j][q]; Else                   for(intQ = (k +1) * (1<< (I-1)) +1; Q <= (k +2) * (1<< (I-1)); q++) T+ = Win[i-1][J] * Win[i-1][Q] *P[j][q]; WIN[I][J]=T; }        DoubleMAXN =-1.0; intWinner =0;  for(inti =1; I <= (1<< N); i++)            if(Win[n][i] > Maxn) MAXN = Win[n][i], winner =i; printf ("%d\n", winner); }    return 0;}
View Code

POJ3071 (Football)

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.