题目大意,1<<n个球队比赛赛程是这样的
1
1 1
1 1 1 1
另dp[i][k]为k队进入第i场的概率
#include<iostream> #include<string.h> #include<stdio.h> using namespace std; const int maxa = (1<<8); double a[maxa][maxa]; double dp[8][maxa]; int main(){ int n; while(scanf("%d", &n)!=EOF){ if(n == -1){ return 0; } for(int i = 0; i < (1<<n); i++){ for(int k = 0; k < (1<<n); k++) scanf("%lf", &a[i][k]); } memset(dp, 0, sizeof(dp)); for(int i = 0; i < (1<<n); i++) dp[0][i] = 1; for(int i = 1; i <= n; i++){ // printf("%d* ", i); for(int k = 0; k < (1<<n); k++){ // printf("%d ", k); for(int j = k/(1<<i)*(1<<i); j < k/(1<<i)*(1<<i)+(1<<i); j++){ if(j/(1<<(i-1)) != k/(1<<(i-1))){ dp[i][k] += dp[i-1][j]*a[k][j]; //printf("%d ", j); } }//puts(""); dp[i][k] = dp[i][k]*dp[i-1][k]; } } /* for(int k = 0; k <= n; k++){ for(int i = 0; i < (1<<n); i++){ printf("%lf ", dp[k][i]); }puts(""); }*/ double maxn = dp[n][0]; //printf("%lf ", maxn); int ans = 0; for(int i = 1; i < (1<<n); i++){ if(dp[n][i] > maxn){ maxn = dp[n][i]; ans = i; } //printf("%lf ", dp[1][i]); } printf("%d ", ans+1); } }