POJ 3071 Football(区间DP)
来源:互联网 发布:冒险岛 攻击矩阵 编辑:程序博客网 时间:2024/06/06 01:55
递推过程中应该考虑的是比赛的层数,比如这样:
[盗图...]
第i个人在第k层比赛获胜的概率:dpki = ∑(dp(k - 1)i * dp(k - 1)j * pij)。
但是如何判断第i个人和第j个在第k层相遇是否合法呢,即是否在同一个子树中?
这篇博客的方法很巧妙:POJ 3071 Football(概率问题) - 窝不是爱酱,喵~~~~ - 博客频道 - CSDN.NET
在第k层比赛的选手,编号(从0开始)写作二进制的第k位不会相同。
#include <iostream>#include <stdlib.h>#include <string.h>#include <stdio.h>using namespace std;#define MAXN (1 << 7) + 10int n;double p[MAXN][130], dp[MAXN][MAXN];int main(){// freopen("3071.in", "r", stdin); while(scanf("%d", &n) && n != -1) { int tot = (1 << n); for(int i = 0; i < tot; i++) for(int j = 0; j < tot; j++) scanf("%lf", &p[i][j]); memset(dp, 0, sizeof(dp)); for(int i = 0; i < tot; i++) dp[0][i] = 1; for(int k = 1; k <= n; k++) for(int i = 0; i < tot; i++) for(int j = 0; j < tot; j++) if(((j >> (k - 1) ) ^ 1) == (i >> (k - 1))) dp[k][i] += dp[k - 1][i] * dp[k - 1][j] * p[i][j]; int ans = 0; for(int i = 0; i < tot; i++) if(dp[n][i] > dp[n][ans]) ans = i; printf("%d\n", ans + 1); } return 0;}
0 0
- POJ 3071 Football(区间DP)
- 【POJ 3071】 Football(DP)
- poj 3071 Football DP
- POJ 3071 Football (概率DP)
- poj 3071 Football(概率dp)
- poj 3071 Football(概率dp)
- [ACM] POJ 3071 Football (概率DP)
- POJ 3071 Football(简单 概率DP)
- POJ 3071-Football(概率dp)
- poj 3071 Football (概率DP)
- POJ 3071 Football (概率dp)
- poj 3071 Football(概率dp)
- poj 3071 Football (概率 dp)
- poj 3071Football(概率dp)
- POJ 3071 Football(概率dp)
- POJ 3071 Football (概率DP)
- POJ 3071 Football(概率DP)
- POJ 3071 Football (概率DP)
- SUSE Linux下设置自启动脚本
- 乱码问题
- 服务器插入新硬盘无法显示#已经解决
- O2O电子商务 营销模式
- Ubuntu 及 Centos 7的Linux环境下安装 Sublime text
- POJ 3071 Football(区间DP)
- 剑指offer系列源码-八皇后问题
- Linux sh与bash 细微差别(运维必备)
- 02_c3p0之c3p0-config.xml配置案例,操作c3p0的jdbcUtil工具类的编写
- java基本数据类型转换
- 你的Android应用完全不需要那么多的权限
- 批量INSERT INTO SELECT和批量REPLACE INTO SELECT
- 从业IT 行业快10年了
- unity3D--数据库