Poj 3071 football (simple probability DP)

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.