首页 > 代码库 > poj 3071 Football

poj 3071 Football

题意:

有2^n支队伍进行比赛,每行给出这支队伍打败各支队伍的几率,求获胜几率最大的队伍

 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include<algorithm> 8 #include<cstring> 9 #include<stdlib.h>10 #include<cmath>11 using namespace std;12 #define pb push_back13 double p[140][140];14 double dp[10][130];15 int need(int x,int ps){16     if(x%(1<<(ps))>=1&&x%(1<<(ps))<=(1<<(ps-1)))17     return x/(1<<ps)*(1<<ps)+(1<<(ps-1))+1;18     if(x%(1<<(ps))==0)19     return (x/(1<<ps)-1)*(1<<ps)+1;20     return x/(1<<ps)*(1<<ps)+1;21 }22 int main(){23     int n;24     while(cin>>n&&n!=-1){25         for(int i=1;i<=(1<<n);i++)26             for(int j=1;j<=(1<<n);j++)27             scanf("%lf",&p[i][j]);28         memset(dp,0,sizeof(dp));29         for(int i=1;i<=(1<<n);i++)30             dp[0][i]=1;31         for(int i=1;i<=n;i++){32             for(int j=1;j<=(1<<n);j++){33                     int kk=need(j,i);34                     for(int k=kk;k<kk+(1<<(i-1));k++)35                         dp[i][j]+=dp[i-1][j]*dp[i-1][k]*p[j][k];36             }37         }38         int pos;39         double mm=0;40         for(int i=1;i<=(1<<n);i++)41         if(dp[n][i]>mm){42             mm=dp[n][i];43             pos=i;44         }45         cout<<pos<<endl;46     }47 }