标签:int 1.0 else ble code pre family strong main
我进行了分组,1组和2组打,3组和4组打,
举个例子,在8进4的比赛中6在2组,和1组的打,1胜出的概率*6打败1的概率,求和之后,再*当前6从上一轮胜出的概率,最后求最大即可。
#include<bits/stdc++.h> using namespace std; int n,m,x; double p[1300][1300]; double f[13][1300]; int main() { cin>>n; m=(1<<n); for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) { cin>>p[i][j]; p[i][j]/=100.0; } for(int i=1;i<=m;i++) f[0][i]=1.0; for(int i=1;i<=n;i++) { x=(1<<(i-1)); int num1,num2; for(int j=1;j<=m;j++) { num1=(j+x-1)/x;//向下取整 if(num1%2==1) num2=num1+1; else num2=num1-1; double sum=0.0; for(int k=(num2-1)*x+1;k<=num2*x;k++) { sum+=p[j][k]*f[i-1][k]; } f[i][j]=sum*f[i-1][j]; } } double Max=0.0; int ans; for(int i=1;i<=m;i++) { if(f[n][i]>Max) { Max=f[n][i]; ans=i; } } cout<<ans; return 0; }
标签:int 1.0 else ble code pre family strong main
原文地址:http://www.cnblogs.com/war1111/p/7412223.html