poj 3071 简单概率dp

题意很清晰,就是问最有可能获得冠军的队伍。

需要注意的是每轮比赛中,每个队都是和自己旁边的一个队比赛,采用淘汰赛制,所以需要决定第i轮的时候j队可以和哪些队比赛,然后求概率dp即可。

状态转移方程:

  dp[i][j] += dp[i - 1][j] * dp[i - 1][k] * p[j][k];

  dp[i][j]表示第i轮j队获胜的概率 = 第i-1轮j队获胜的概率 * 第i-1轮k队获胜的概率 * j队打败k队的概率(之和)。

  前提是j和k在第i轮可能遇到。

  判断方法: ( j >> ( i - 1 ) ) ^ 1 == k >> ( i - 1 )

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 using namespace std;
 5
 6 const int N = 8;
 7 const int M = 1 << 7;
 8 double dp[N][M];
 9 double p[M][M];
10
11 int main ()
12 {
13     int n, m;
14     while ( scanf("%d", &n) != EOF )
15     {
16         if ( n == -1 ) break;
17         m = 1 << n;
18         for ( int i = 0; i < m; i++ )
19         {
20             for ( int j = 0; j < m; j++ )
21             {
22                 scanf("%lf", &p[i][j]);
23             }
24         }
25         for ( int j = 0; j < m; j++ )
26         {
27             dp[0][j] = 1.0;
28         }
29         for ( int i = 1; i <= n; i++ )
30         {
31             for ( int j = 0; j < m; j++ )
32             {
33                 dp[i][j] = 0;
34                 for ( int k = 0; k < m; k++ )
35                 {
36                     if ( ( ( j >> ( i - 1 ) ) ^ 1 ) == ( k >> ( i - 1 ) ) )
37                     {
38                         dp[i][j] += dp[i - 1][j] * dp[i - 1][k] * p[j][k];
39                     }
40                 }
41             }
42         }
43         int ans = 0;
44         for ( int j = 1; j < m; j++ )
45         {
46             if ( dp[n][j] > dp[n][ans] )
47             {
48                 ans = j;
49             }
50         }
51         printf("%d\n", ans + 1);
52     }
53     return 0;
54 }
时间: 2024-12-22 10:35:14

poj 3071 简单概率dp的相关文章

[ACM] POJ 3071 Football (概率DP)

Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2875   Accepted: 1462 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all teams still in the

POJ 3071 Football (概率DP)

题意:给定 2的n次方 个团队对每个队的战胜的概率,一块要打 n 场,每场都是 1 对 2, 2 对 3,每次都取赢的一方,问你最后谁是冠军的概率最大. 析:dp[i][j] 表示 第 i 场 j 胜的概率,每次只要算 i 相邻的且不是已经打过的 2 i-1次方个队,最后再选出概率最大的就好. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include &l

poj 3071 Football (概率DP水题)

G - Football Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, …, 2n. In each round of the tournament, all teams

POJ 3071 Football(简单 概率DP)

Football 原文链接:http://blog.csdn.net/xuechelingxiao/article/details/38520105 大意:2^n 个球队进行单场淘汰赛,每两只球队之间比赛会有胜负的概率,问最后谁夺冠的概率最大. 思路:简单的概率DP问题,主要是怎么处理哪两个球队比赛的问题. DP方程为 dp[i][j] = ∑(dp[i-1][j]*dp[i-1][k]*p[j][k]); //dp[i][j]表示第 i 轮的时候,第 j 支队伍赢的概率.. 对于其中位运算,可

Aeroplane chess(简单概率dp)

Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). Whe

简单概率DP——hdu4405

题目描述: Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6

POJ 3071-Football(概率dp)

Football Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3145   Accepted: 1591 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all teams still in the

poj 1322 Chocolate (概率dp)

///有c种不同颜色的巧克力,一个个的取,当发现有相同的颜色的就吃掉,去了n个后,到最后还剩m个的概率 ///dp[i][j]表示取了i个还剩j个的概率 ///当m+n为奇时,概率为0 # include <stdio.h> # include <algorithm> # include <string.h> # include <iostream> using namespace std; double dp[1010][1010]; int main()

POJ 3156 - Interconnect (概率DP+hash)

题意:给一个图,有些点之间已经连边,现在给每对点之间加边的概率是相同的,问使得整个图连通,加边条数的期望是多少. 此题可以用概率DP+并查集+hash来做. 用dp(i,j,k...)表示当前的每个联通分量的点数分别是i,j,k...(连通分量的个数不固定)时,加边的期望. 这样以dp(i,j,k)为例分析状态转移的过程,dp(i,j,k)=p1*dp(i,j,k)+p2*dp(i+j,k)+p3*dp(i,j+k)+p4*dp(j,i+k)+1. 终止条件是dp(n)=0,因为此时图一定联通,