• Football 概率DP poj3071


                                                                                                 Football
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 2590   Accepted: 1315

    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 are 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 are eliminated. After n rounds, only one team remains undefeated; this team is declared the winner.

    Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.

    Input

    The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value on the ith line represents pij. The matrix P will 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 that you 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 is guaranteed that the difference in win probability for the top two teams will be at least 0.01.

    Sample Input

    2
    0.0 0.1 0.2 0.3
    0.9 0.0 0.4 0.5
    0.8 0.6 0.0 0.6
    0.7 0.5 0.4 0.0
    -1

    Sample Output

    2


     1 #include <iostream>
     2 #include <stdio.h>
     3 using namespace std;
     4 double a[1<<10][1<<10];
     5 double dp[10][1<<10];
     6 int main()
     7 {
     8     int n,i,j,k;
     9     while(cin>>n)
    10     {
    11         if(n==-1)break;
    12         for(i=0; i<1<<n; i++)
    13             for(j=0; j<1<<n; j++)
    14                 scanf("%lf",&a[i][j]);
    15         for(i=0; i<1<<n; i++)dp[0][i]=1;
    16         for(i=1;i<=n;i++)
    17         {
    18             for(j=0;j<1<<n;j++)
    19             {
    20                 dp[i][j]=0;
    21                 int start=((j>>(i-1))^1)<<(i-1);
    22                 int num=1<<(i-1);
    23                 for(k=start;k<num+start;k++)
    24                 dp[i][j]+=dp[i-1][j]*dp[i-1][k]*a[j][k];
    25             }
    26         }
    27    double max=0,an=0;
    28    for(i=0;i<1<<n;i++)
    29    {
    30        if(dp[n][i]>max)
    31        {
    32            max=dp[n][i];
    33            an=i;
    34        }
    35    }
    36    cout<<an+1<<endl;
    37     }
    38 }
    View Code
  • 相关阅读:
    <Error>: CGContextRestoreGState
    Google 常用镜像收集
    NSCharacterSet 详解
    JAVA并发,CyclicBarrier
    JAVA并发,CountDownLatch使用
    JAVA并发,经典死锁案例-哲学家就餐
    Git-常用命令集合
    (转)《JAVA与模式》之模板方法模式
    JAVA并发,同步锁性能测试
    《转》JAVA并发编程:volatile关键字解析
  • 原文地址:https://www.cnblogs.com/ERKE/p/3576375.html
Copyright © 2020-2023  润新知