[POJ3071] Football
模拟,dp[i][j]表示第i局j获胜的概率
轻易~
1 #include<cstdio> 2 using namespace std; 3 #define maxn 1000 4 double dp[10][maxn],p[maxn][maxn]; 5 int n; 6 void getdp(int x,int y){ 7 int len=1<<(x-1); 8 for(int i=1;i<=len;i++){ 9 dp[x][y+i]=dp[x][y+len+i]=0; 10 for(int j=1;j<=len;j++){ 11 dp[x][y+i]+=p[y+i][y+len+j]*dp[x-1][y+len+j]; 12 dp[x][y+len+i]+=p[y+len+i][y+j]*dp[x-1][y+j]; 13 } 14 dp[x][y+i]*=dp[x-1][y+i]; 15 dp[x][y+len+i]*=dp[x-1][y+len+i]; 16 } 17 } 18 int Max(int x,int y){ return dp[n][x]>dp[n][y]?x:y; } 19 int main(){ 20 while(1){ 21 scanf("%d",&n); 22 if(n==-1)break; 23 for(int i=1;i<=1<<n;i++) 24 for(int j=1;j<=1<<n;j++) 25 scanf("%lf",&p[i][j]); 26 for(int i=1;i<=1<<n;i+=2) 27 dp[1][i]=p[i][i+1],dp[1][i+1]=p[i+1][i]; 28 for(int i=2;i<=n;i++) 29 for(int j=1;j<=1<<n;j+=1<<i) 30 getdp(i,j-1); 31 int ans=0; 32 for(int i=1;i<=1<<n;i++) 33 ans=Max(ans,i); 34 printf("%d\n",ans); 35 } 36 }