标签:pre int amp double scan ++ strong 概率 main
1.POJ 3744
详解:
2.POJ - 3071 Football
代码:
#include <cstdio>
#include <cstring>
using namespace std;
const int N=(1<<7)+5;
double p[N][N],win[N][10];
int main()
{
int n;
while(scanf("%d",&n),n!=-1)
{
int m=1<<n;
double maxn=0;
int num=1;
for(int i=1;i<=m;i++)
{
for(int j=1;j<=m;j++)
scanf("%lf",&p[i][j]);
}
memset(win,0,sizeof(win));
for(int i=1;i<=m;i++)
win[i][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{//cout<<"j="<<j<<" : ";
int len=1<<i;
int s=j/len;
if(j%len==0)
s--;
s*=len;//cout<<s+1<<"->"<<s+len<<" ";
int l=(j>(s+len/2)?(s+1):(s+len/2+1));
int r=(j>s+len/2?s+len/2:s+len);
//cout<<"l= "<<l<<" r="<<r<<" ";
for(int k=l;k<=r;k++)//第i轮第j个选手需要比较的区间
{
if(k==j)
continue;
win[j][i]+=win[j][i-1]*win[k][i-1]*p[j][k];
}
//cout<<win[j][i]<<endl;
if(i==n&&win[j][i]>maxn)
{
maxn=win[j][i];
num=j;
}
}
}//cout<<maxn<<endl;
printf("%d\n",num);
}
return 0;
}
标签:pre int amp double scan ++ strong 概率 main
原文地址:https://www.cnblogs.com/1024-xzx/p/12377965.html