随笔 - 228  文章 - 0 评论 - 7 阅读 - 55351
< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

                                                                                             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
复制代码

 

posted on   ERKE  阅读(183)  评论(0编辑  收藏  举报
编辑推荐:
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
· 你所不知道的 C/C++ 宏知识
· 聊一聊 操作系统蓝屏 c0000102 的故障分析
阅读排行:
· DeepSeek V3 两周使用总结
· 回顾我的软件开发经历(1)
· C#使用yield关键字提升迭代性能与效率
· 低成本高可用方案!Linux系统下SQL Server数据库镜像配置全流程详解
· 4. 使用sql查询excel内容
点击右上角即可分享
微信分享提示