Football
Link: http://blog.csdn.net/xuechelingxiao/article/details/38520105
2 ^ n teams in a single knockout match, each of which has the highest probability of winning the championship.
Idea: the simple probability DP problem is mainly about how to deal with the problem of which two teams are playing.
The DP equation is DP [I] [J] = Σ (DP [I-1] [J] * DP [I-1] [k] * P [J] [k]); // DP [I] [J] indicates the probability that the J team will win in the I round. ,
For bit operations, you can use a binary tree to more intuitive understanding (j> (I-1) ^ 1) with (k> (I-1) represents the two subnodes of a parent node, when (j> (I-1) ^ 1) = (k> (I-1, it indicates that two subnodes are competitive, and the winner will update to the secondary node.
1 #include <stdio.h> 2 #include <string.h> 3 4 int n; 5 double p[1000][1000]; 6 double dp[10][1000]; 7 8 int main() 9 {10 while(~scanf("%d", &n) && n != -1){11 for(int i = 0; i < (1<<n); ++i){12 for(int j = 0; j < (1<<n); ++j){13 scanf("%lf", &p[i][j]);14 }15 }16 memset(dp, 0, sizeof(dp));17 18 for(int i = 0; i < (1<<n); ++i){19 dp[0][i] = 1;20 }21 for(int i = 1; i <= n; ++i){22 for(int j = 0; j < (1<<n); ++j){23 for(int k = 0; k < (1<<n); ++k){24 if(((j>>(i-1))^1) == (k>>(i-1)))25 dp[i][j] += dp[i-1][k]*dp[i-1][j]*p[j][k];26 }27 }28 }29 30 double ans = -1;31 int Ans = -1;32 for(int i = 0; i < (1<<n); ++i){33 if(dp[n][i] > ans){34 ans = dp[n][i];35 Ans = i;36 }37 }38 printf("%d\n", Ans+1);39 }40 41 return 0;42 }Poj 3071