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-heapq
heapq 模块,实现了堆序列算法,也叫优先序列算法.heap(堆)是每个父节点都小于等于子节点的树,同时所有节点k都满足 heap[k] <= heap[2*k+1] 和 heap[k] &l ...
- mysqldump: Got error: 1356 mysqldump的重要参数--force
一个MySQL的备份突然变小了很多,但实际的数据量却一直在增长.备份脚本也没有调整过.为什么呢? 重现了一下备份过程,发现备份中遇到了如下错误: mysqldump: Got error: 1356: ...
- 微信小程序开发 [05] wx.request发送请求和妹纸图
1.wx.request 微信小程序中用于发起网络请求的API就是wx.request了,具体的参数太多,此处就不再一一详举了,基本使用示例如下: wx.request({ url: 'test.ph ...
- scala-数组操作
package com.bigdata import scala.collection.mutable.ArrayBuffer object ArrayO { def main(args: Array ...
- Spark(Python) 从内存中建立 RDD 的例子
Spark(Python) 从内存中建立 RDD 的例子: myData = ["Alice","Carlos","Frank"," ...
- CS299笔记:广义线性模型
指数分布族 我们称一类分布属于指数分布族(exponential family distribution),如果它的分布函数可以写成以下的形式: \[ \begin{equation} p(y;\et ...
- CF1096G Lucky Tickets
https://www.luogu.org/problemnew/show/CF1096G 显然dp出用\(\frac{n}{2}\)个数能拼出来的每个数的方案数,平方相加就行了,dp显然ntt+快速 ...
- 表单设置 disabled 后无法传值到后台的解决办法
在提交 from 表单时,下面的 input 无法正常提交给后台, 发现,如果input的字段设为disabled,该表单是无法提交的. <input type="text" ...
- 2PC/3PC到底是啥
讨论 提到2PC/3PC首先想到的是它是一致性协议,而且经常把它和Paxos协议放在一起比较,并且经常看到这样的说法"世上只有一种一致性算法,那就是Paxos",2PC/3PC并不 ...
- stl源码剖析 详细学习笔记deque(2)
//---------------------------15/3/13---------------------------- self&operator++() { ++cur; if(c ...