tag:概率dp
思路:
Round1 :
0 play with 1
2 play with 3
4 play with 5
...
Round 2:
0 can play with 2 or 3 vice versa
1 can play with 2 or 3 vice versa
4 can play with 6 or 7 vice versa
5 can play with 6 or 7 vice versa
...
Round i
player j can play with k
only (j>>(i-1)) == ( (k>>(i-1))^1)
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstdio>
using namespace std;
#define maxn ((1<<7)+1)
double dp[8][maxn];
double p[maxn][maxn];
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
if(n==-1)
break;
memset(dp,0,sizeof(dp));
int m=(1<<n);
for(int i=0;i<m;i++)
dp[0][i]=1;
for(int i=0;i<m;i++)
for(int j=0;j<m;j++)
scanf("%lf",&p[i][j]);
for(int i=1;i<=n;i++)
for(int j=0;j<m;j++)
{
for(int k=0;k<m;k++)
{
if((j>>(i-1)) == ((k>>(i-1))^1))
dp[i][j]+=dp[i-1][k]*dp[i-1][j]*p[j][k];
}
}
int ans=1;
double mx=0;
for(int i=0;i<m;i++)
{
if(mx<dp[n][i])
{
mx=dp[n][i];
ans=i;
}
}
printf("%d\n",ans+1);
}
return 0;
}