Codeforces 859D - Third Month Insanity
题意
有 \(2^n\) 个人要进行比赛,每次 \(2i\) 与 \(2i+1\) 号人进行比赛(\(i\in [0,2^{n-1})\) )。这一轮中赢的人进入下一轮。下一轮比赛的时候把进入这一轮的人按编号排好,仍然是像之前那样相邻的进行一次比赛。最后只剩下一个人。
数据给出对于 \(x,y\) ,\(x\) 打赢 \(y\) 的概率。
第 \(i\) 轮比赛会角逐出 \(2^{n-i}\) 个赢家。我们要在比赛开始前,猜每轮的赢家(一轮的赢家一定要是上一轮的赢家)。第 \(i\) 轮每猜中一个赢家就会得到 \(2^{i-1}\) 的得分。
求最大的期望得分。
\(n\le 6\) 。
分析
只有猜到了与最终赢家相关的人才可能有得分。
轮数编号为 \([0,n)\) 。
设 \(f[i][x]\) 为 \(x\) 在第 \(i\) 轮胜利,只统计与 \(x\) 有关的人(递归地定义,与 \(x\) 比赛过的人以及与他们有关的人)的猜测的得分。
这是容易转移的。设 \(o(i,x)\) 表示可能在第 \(i\) 轮与 \(x\) 比赛的人的集合,那么
\]
其中 \(p[i][x]\) 表示 \(x\) 在第 \(i\) 轮胜利的概率。 其实就是 \(x\) 一定要赢,看预测哪个对手得分比较高。
\(p[i][x]\) 也是容易得到的
\]
\(w[x][v]\) 为 \(x\) 打败 \(v\) 的概率。
代码
#include<bits/stdc++.h>
using namespace std;
inline char nchar() {
static const int bufl=1<<20;
static char buf[bufl],*a=NULL,*b=NULL;
return a==b && (b=(a=buf)+fread(buf,1,bufl,stdin),a==b)?EOF:*a++;
}
inline int read() {
int x=0,f=1;
char c=nchar();
for (;!isdigit(c);c=nchar()) if (c=='-') f=-1;
for (;isdigit(c);c=nchar()) x=x*10+c-'0';
return x*f;
}
template<typename T> inline void Max(T &x,T y) {if (y>x) x=y;}
const int maxn=6;
const int maxs=1<<maxn;
double a[maxs][maxs],p[maxn][maxs],f[maxn][maxs];
int n,s,bin[maxs];
vector<int> o[maxs][maxn];
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in","r",stdin);
#endif
for (int i=2;i<maxs;++i) bin[i]=bin[i>>1]+1;
n=read(),s=1<<n;
for (int i=0;i<s;++i) for (int j=0;j<s;++j) {
a[i][j]=read()/100.;
if (i!=j) o[i][bin[i^j]].push_back(j);
}
for (int i=0;i<s;++i) f[0][i]=p[0][i]=a[i][o[i][0][0]];
for (int i=1;i<n;++i) for (int j=0;j<s;++j) {
double &r=p[i][j]=0;
for (int x:o[j][i]) r+=p[i-1][x]*a[j][x];
r*=p[i-1][j];
}
for (int i=1;i<n;++i) for (int j=0;j<s;++j) {
double &r=f[i][j]=0;
for (int x:o[j][i]) Max(r,f[i-1][x]);
r+=f[i-1][j]+p[i][j]*(1<<i);
}
double ans=*max_element(f[n-1],f[n-1]+s);
printf("%.12lf\n",ans);
return 0;
}
Codeforces 859D - Third Month Insanity的更多相关文章
- 【CF MEMSQL 3.0 D. Third Month Insanity】
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 724
题目链接: http://codeforces.com/contest/724 A. Checking the Calendar time limit per test 1 second memory ...
- [codeforces 260]B. Ancient Prophesy
[codeforces 260]B. Ancient Prophesy 试题描述 A recently found Ancient Prophesy is believed to contain th ...
- Codeforces Good Bye 2015 A. New Year and Days 水题
A. New Year and Days 题目连接: http://www.codeforces.com/contest/611/problem/A Description Today is Wedn ...
- Codeforces 631C. Report 模拟
C. Report time limit per test:2 seconds memory limit per test:256 megabytes input:standard input out ...
- Codeforces Round #344 (Div. 2) C. Report 其他
C. Report 题目连接: http://www.codeforces.com/contest/631/problem/C Description Each month Blake gets th ...
- codeforces B. Calendar 解题报告
题目链接:http://codeforces.com/problemset/problem/304/B 题目意思:给出两个日期,需要算出这两个日期之间有多少日. 细心模拟就可以了.特别要注意的是,两个 ...
- Codeforces Round 363 Div. 1 (A,B,C,D,E,F)
Codeforces Round 363 Div. 1 题目链接:## 点击打开链接 A. Vacations (1s, 256MB) 题目大意:给定连续 \(n\) 天,每天为如下四种状态之一: 不 ...
- 【codeforces 760A】Petr and a calendar
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
随机推荐
- Python2.7-textwrap
textwrap主要针对英文的文本 模块内方法: wrap(text[, width, ...]),把text分成每行width长,返回一个列表,没有结尾的\n.fill(text[, width, ...
- docker push images login -u harbor 问题记录 https 证书
1.[root@dev-100 Desktop]# docker login -u clouder -p engine harbor.xiaowei.com 2.docker tag busybox: ...
- js中数组的使用
使用js时候,很多情况下要使用数组.就写写数组中一些常用的方法. js中定义一个数组,一般有以下2种方法. 1. var arr = new Array(3); // 声明数组有3个元素 arr[0] ...
- 20155334 曹翔 Exp3 免杀原理与实践
20155334 曹翔 Exp3 免杀原理与实践 小记:这次实验,困难重重,失败练练,搞得我们是心急如焚,焦头烂额,哭爹喊娘 一.基础问题回答 杀软是如何检测出恶意代码的? 每个杀软都有自己的检测库, ...
- [GitHub]GitHub for Windows离线安装的方法
这几天一直在尝试安装GitHub for windows ,安装程序是从https://windows.github.com/ 下载到的OneClick 部署程序,版本号为2.11.0.5.可能是因为 ...
- Linux中tty、pty、pts的概念区别 转载
基本概念: > tty(终端设备的统称): tty一词源于Teletypes,或teletypewriters,原来指的是电传打字机,是通过串行线用打印机键盘通过阅读和发送信息的东西,后来这东西 ...
- 校内模拟赛 Label
题意: n个点m条边的无向图,有些点有权值,有些没有.边权都为正.给剩下的点标上数字,使得$\sum\limits_{(u,v)\in E}len(u,v) \times (w[u] - w[v]) ...
- 理解 NgModelController 中相关方法和属性
1. 理解$formatters和$parsers方法 angular的双向绑定可以实现view和model中的值自动同步,但有时候我们不想让用户输入的(view值)和发送给后台的(model值)并不 ...
- Java Web应用中支持跨域请求
转载:https://blog.csdn.net/lmy86263/article/details/51724221 由于工程合作开发的需要,后台的应用要能支持跨域访问,但是在这个跨域访问“时好时坏” ...
- springboot @PropertySource
@ConfigurationProperties(prefix="person") 默认加载全局配置文件 application.properties或application.ym ...