【POJ3071】Football - 状态压缩+期望 DP
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 tournament are placed in a list in order of increasing index. Then, the first team in the list plays the second team, the third team plays the fourth team, etc. The winners of these matches advance to the next round, and the losers are eliminated. After n rounds, only one team remains undefeated; this team is declared the winner.
Given a matrix P = [pij] such that pij is the probability that team i will beat team j in a match determine which team is most likely to win the tournament.
Input
The input test file will contain multiple test cases. Each test case will begin with a single line containing n (1 ≤ n ≤ 7). The next 2n lines each contain 2n values; here, the jth value on the ith line represents pij. The matrix P will satisfy the constraints that pij = 1.0 − pji for all i ≠ j, and pii = 0.0 for all i. The end-of-file is denoted by a single line containing the number −1. Note that each of the matrix entries in this problem is given as a floating-point value. To avoid precision problems, make sure that you use either the double data type instead of float.
Output
The output file should contain a single line for each test case indicating the number of the team most likely to win. To prevent floating-point precision issues, it is guaranteed that the difference in win probability for the top two teams will be at least 0.01.
题目大意
给你$2^n$个球队,必须相邻的球队才可以比赛,在告诉你i球队战胜j球队的概率,问最后哪支球队赢得概率最大。
思路
设$f_{i,j}$表示第$i$次比赛队伍$j$获胜的概率,枚举与$j$比赛的$k$,可得$f_{i,j} = \sum_{k=1}^{2^n}f_{i-1,j}*f_{i-1,k}*p_{j,k}*[$ $\text{j与k相邻} ]$
判断相邻先<<(i-)再用异或(^)运算判断一下即可
/************************************************
*Author : lrj124
*Created Time : 2018.09.30.19:13
*Mail : 1584634848@qq.com
*Problem : poj3071
************************************************/
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
const int maxn = (1<<7) + 10;
double p[maxn][maxn],f[maxn][maxn];
int n;
int main() {
while (cin >> n) {
if (n == -1) break;
memset(f,0,sizeof(f));
for (int i = 1;i <= (1<<n);i++) {
f[0][i] = 1;
for (int j = 1;j <= (1<<n);j++) scanf("%lf",&p[i][j]);
}
for (int i = 1;i <= (1<<n);i++)
for (int j = 1;j <= (1<<n);j++)
for (int k = 1;k <= (1<<n);k++)
if ((((j-1)>>(i-1))^1) == ((k-1)>>(i-1)))
f[i][j] += f[i-1][j]*f[i-1][k]*p[j][k];
double Max = 0;
int ans;
for (int i = 1;i <= (1<<n);i++)
if (f[n][i] > Max) {
Max = f[n][i];
ans = i;
}
printf("%d\n",ans);
}
return 0;
}
【POJ3071】Football - 状态压缩+期望 DP的更多相关文章
- hdu 4649 Professor Tian 反状态压缩+概率DP
思路:反状态压缩——把数据转换成20位的01来进行运算 因为只有20位,而且&,|,^都不会进位,那么一位一位地看,每一位不是0就是1,这样求出每一位是1的概率,再乘以该位的十进制数,累加,就 ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4739 Zhuge Liang's Mines (状态压缩+背包DP)
题意 给定平面直角坐标系内的N(N <= 20)个点,每四个点构成一个正方形可以消去,问最多可以消去几个点. 思路 比赛的时候暴力dfs+O(n^4)枚举写过了--无意间看到有题解用状压DP(这 ...
- ACM学习历程—HDU1584 蜘蛛牌(动态规划 && 状态压缩 || 区间DP)
Description 蜘蛛牌是windows xp操作系统自带的一款纸牌游戏,游戏规则是这样的:只能将牌拖到比她大一的牌上面(A最小,K最大),如果拖动的牌上有按顺序排好的牌时,那么这些牌也跟着一起 ...
- 洛谷 P2051 [AHOI2009]中国象棋 状态压缩思想DP
P2051 [AHOI2009]中国象棋 题意: 给定一个n*m的空棋盘,问合法放置任意多个炮有多少种情况.合法放置的意思是棋子炮不会相互打到. 思路: 这道题我们可以发现因为炮是隔一个棋子可以打出去 ...
- 【Luogu】P2258子矩阵(状态压缩,DP)
233今天蒟蒻我连文化课都没听光想着这个了 然后我调了一下午终于过了!!! 一看数据范围似乎是状压,然而216等于65536.开一个65536*65536的二维数组似乎不太现实. 所以Rqy在四月还是 ...
- [HNOI2012]集合选数(构造,状态压缩,DP)
神仙题. 莫名其妙的就试一试把所有数放进一个类似矩阵的东西里面. 首先把 \(1\) 放到左上角,然后在每个数的右边放它的 \(3\) 倍(大于 \(n\) 就不用放了),下面放它的 \(2\) 倍( ...
- 过河(状态压缩,dp)
描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上 ...
- ZOJ 3502 Contest <状态压缩 概率 DP>
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3502 #include <iostream> #incl ...
随机推荐
- 获取字符串指定字符的第n次出现位置
create function uf_findx (@text nvarchar(max),@find_x varchar(200),@find_n int)returns intasbegin -- ...
- 10种常见OOM分析——手把手教你写bug
点赞+收藏 就学会系列,文章收录在 GitHub JavaKeeper ,N线互联网开发必备技能兵器谱,笔记自取 在<Java虚拟机规范>的规定里,除了程序计数器外,虚拟机内存的其他几个运 ...
- centos7.5安装gdal编译环境
安装准备的环境: 名称 类型与版本 软件连接 服务器 linux-centos7.5 jdk 1.8.0_25 ant 1.9.14 http://mirror.bit.edu.cn/apac ...
- VS Code小白使用教程
本文来自作者:你不知道的巨蟹 原文链接 https://www.cnblogs.com/tu-0718/p/10935910.html,如有侵权,则可删除. 前言 现在使用Vscode编码的人越来越多 ...
- LRU cache缓存简单实现
LRU cache LRU(最近最少使用)是一种常用的缓存淘汰机制.当缓存大小容量到达最大分配容量的时候,就会将缓存中最近访问最少的对象删除掉,以腾出空间给新来的数据. 实现 (1)单线程简单版本 ( ...
- 第四章 常用API(上)
4.1.Object类 描述:该类是所有类的最终根类 方法 描述 public boolean equals(Object obj) 表示某个其它对象是否"等于"此对象 publi ...
- 哇咔咔干货来啦:PowerJob 原理剖析之 Akka Toolkit
本文适合有 Java 基础知识的人群 作者:HelloGitHub-Salieri HelloGitHub 推出的<讲解开源项目>系列. Akka is a toolkit for bui ...
- 基于个人理解的springAOP部分源码分析,内含较多源码,慎入
本文源码较多,讲述一些个人对spring中AOP编程的一个源码分析理解,只代表个人理解,希望能和大家进行交流,有什么错误也渴求指点!!!接下来进入正题 AOP的实现,我认为简单的说就是利用代理模式,对 ...
- HTML <body> 标签
HTML <body> 标签 实例 一个简单的 HTML 文档,包含尽可能少的必需的标签: <!DOCTYPE html> <html> <head> ...
- ZROI 提高十连测 Day1
第一天的提高模拟测 考前特意睡了20min 还是歇菜了,果然自己菜是真实的. 题目质量海星 但是我都不会这是真的...题目由于是花钱买的这里就不放了 LINK:problem 熟悉我的人应该都知道账号 ...