确定好对手就简单了。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
double a[150][150];
double dp[9][150];
int n;
void solve()
{
memset(dp,0,sizeof(dp));
for(int i=0;i<=(1<<n);i++)
dp[0][i]=1;
for(int i=1;i<=n;i++)
{
int r=1<<(i-1),l=1<<i;
for(int j=1;j<=(1<<n);j+=l)
{
for(int k=j;k<j+l;k++)
{
if(k<j+r)
for(int t=j+r;t<j+l;t++)
{
dp[i][k]+=dp[i-1][k]*dp[i-1][t]*a[k][t];
}
else
for(int t=j;t<j+r;t++)
dp[i][k]+=dp[i-1][k]*dp[i-1][t]*a[k][t];
}
}
}
int cur;
double cnt=0;
for(int i=0;i<=(1<<n);i++)
if(dp[n][i]>cnt)
{
cnt=dp[n][i];
cur=i;
}
cout<<cur<<endl;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(n==-1) break;
for(int i=1;i<=(1<<n);i++)
for(int j=1;j<=(1<<n);j++)
scanf("%lf",&a[i][j]);
solve();
}
return 0;
}