2018.09.01 poj3071Football(概率dp+二进制找规律)
传送门
概率dp简单题。
设f[i][j]表示前i轮j获胜的概率。
如果j,k能够刚好在第i轮相遇,找规律可以发现j,k满足:
(j−1)>>(i−1)" role="presentation" style="position: relative;">(j−1)>>(i−1)(j−1)>>(i−1)^1==(k−1)>>(i−1)" role="presentation" style="position: relative;">1==(k−1)>>(i−1)1==(k−1)>>(i−1)。
简单举个例子?
假设有八个人,对应下来二进制为:000,001,010,011,100,101,110,111(注意要减一)。
对应上面的看一下应该就秒懂了。
比如说第一轮中,000和001是一组的,因为它们第0位不同,其余位相同。
然而第一轮中,001和010不是一组的,因为它们第1位也不同。
比如说第二轮中,000可以和011是一组的,因为它们第1位是不同的,且第2位相同。
但是000和110不是一组的,因为它们第2位不同。
于是就有了状态转移方程:
f[i][j]=∑j,k可以在一组f[i−1][j]∗f[i−1][k]∗p[i][j]" role="presentation" style="position: relative;">f[i][j]=∑j,k可以在一组f[i−1][j]∗f[i−1][k]∗p[i][j]f[i][j]=∑j,k可以在一组f[i−1][j]∗f[i−1][k]∗p[i][j]
解释:
前i-1轮j,k必须不输,且j必须在这一轮战胜k。
代码:
#include<iostream>
#include<cstdio>
#define N 150
using namespace std;
double p[N][N],f[N][N];
int n,len;
int main(){
while(scanf("%d",&len)){
if(len==-1)break;
n=1<<len;
for(int i=1;i<=n;++i)for(int j=1;j<=n;++j)scanf("%lf",&p[i][j]),f[i][j]=0;
for(int i=1;i<=n;++i)f[0][i]=1;
for(int k=1;k<=len;++k){
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j){
if((((i-1)>>(k-1))^1)==((j-1)>>(k-1)))
f[k][i]+=f[k-1][i]*f[k-1][j]*p[i][j];
}
}
}
double ans=0;
int pos=0;
for(int i=1;i<=n;++i)if(ans<f[len][i])ans=f[len][i],pos=i;
printf("%d\n",pos);
}
return 0;
}
2018.09.01 poj3071Football(概率dp+二进制找规律)的更多相关文章
- # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor
E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...
- 2018 北京区域赛 I - Palindromes (找规律)
题目 HihoCoder - 1878 题目大意 给出k,让求出第k个回文数(k的“长度”不超过1e5) 题解 之前做过类似的题,是统计各阶段的数找到第K个回文数,但这里K太大,需要寻找新的方法. 打 ...
- 2018.09.01 loj#2330. 「清华集训 2017」榕树之心(树形dp)
传送门 树形dp好题啊. 我们用w[i]" role="presentation" style="position: relative;">w[ ...
- 2018.09.01 hdu4405 Aeroplane chess (期望dp)
传送门 期望dp简单题啊. 不过感觉题意不太对. 手过了一遍样例发现如果有捷径必须走. 这样的话就简单了啊. 设f[i]" role="presentation" sty ...
- 2018.09.01 独立集(树形dp)
描述 给定一颗树(边权为1),选取一个节点子集,使得该集合中任意两个节点之间的距离都大于K.求这个集合节点最多是多少 输入 第一行是两个整数N,K 接下来是N-1行,每行2个整数x,y,表示x与y有一 ...
- LOJ #2540. 「PKUWC 2018」随机算法(概率dp)
题意 LOJ #2540. 「PKUWC 2018」随机算法 题解 朴素的就是 \(O(n3^n)\) dp 写了一下有 \(50pts\) ... 大概就是每个点有三个状态 , 考虑了但不在独立集中 ...
- HDU 1203 I NEED A OFFER (01背包&&概率dp)
M - I NEED A OFFER! Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 2018.09.01 09:22 Exodus
Be careful when writing in the blog garden. Sometimes you accidentally write something wrong, and yo ...
- 2018.09.01 09:08 Genesis
Nothing to think about, I don't know where to start, the mastery of learning is not an easy task, yo ...
随机推荐
- leetcode242
public class Solution { public bool IsAnagram(string s, string t) { Dictionary<char, int> dic ...
- shiro与threamleaf的整合
1.添加依赖 2.在配置类中添加shiroDialect
- maven的小知识
一.下载及安装 1.1 下载maven 3.1.1 先到官网http://maven.apache.org/download.cgi 下载最新版本(目前是3.1.1 ),下载完成后,解压到某个目录(本 ...
- Struts2 利用AJAX 导出大数据设置遮罩层
Struts2 利用AJAX 导出大数据设置遮罩层 需求背景: 每次我们导出excel的时候 ,如果数据量很大,导出花费的时间会很长,页面却有没人任何反应,这个时候用户会认为系统有问题,要么关了页面, ...
- Data Guard 介绍
- k8s 问题
kubelet: Orphaned pod "4db449f0-4eaf-11e8-94ab-90b8d042b91a" found, but volume paths are s ...
- clusterProfiler包
1)enrichGO:(GO富集分析) 描述:GO Enrichment Analysis of a gene set. Given a vector of genes, this function ...
- UnicodeEncodeError: ‘ascii’ codec can’t encode
[UnicodeEncodeError: ‘ascii’ codec can’t encode] Python默认环境编码通过下面的方法可以获取: 基本上是ascii编码方式,由此Python自然调用 ...
- SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,MyBatis)的区别
SSH 通常指的是 Struts2 做前端控制器,Spring 管理各层的组件,Hibernate 负责持久化层. SSM 则指的是 SpringMVC 做前端控制器,Spring 管理各层的组件,M ...
- Chip Factory(01字典树)
Chip Factory http://acm.hdu.edu.cn/showproblem.php?pid=5536 Time Limit: 18000/9000 MS (Java/Others) ...