直接模拟比赛过程。
ans[i][j]:第i次比赛,第j个人获胜的概率。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
double maps[1001][1001];
double ans[1001][1001];
int main()
{int n,m,i,j,k;while(~scanf("%d",&m)&&(m!=-1)){n=1<<m;for(i=1;i<=n;i++){for(j=1;j<=n;j++){scanf("%lf",&maps[i][j]);}}memset(ans,0,sizeof(ans));for(j=1;j<=n;j++)ans[0][j]=1.0;int leap=0;int ts;for(i=1;i<=m;i++){leap=1;ts=1<<(i-1);for(j=1;j<=n;j++){int st,ed;st=j-(j-1)%ts+leap*ts;ed=j-(j-1)%ts+leap*ts+ts-1;for(k=st;k<=ed;k++){ans[i][j]+=ans[i-1][j]*ans[i-1][k]*maps[j][k];}if(j%ts==0)leap=-leap;}}double maxx=0;int st=1;for(i=1;i<=n;i++){if(ans[m][i]>maxx){maxx=ans[m][i];st=i;}}cout<<st<<endl;}
}