CodeForces
来源:互联网 发布:毒品网络 豆瓣 编辑:程序博客网 时间:2024/06/11 19:40
传送门:Codeforces 859D
题意:有 2^n 个队伍进行比赛,每次都是编号相邻的的两队伍比赛,胜出的晋级下一轮,失败的淘汰,这样n轮过后只剩一只队伍时停止。每一场比赛你都可以赌某个队伍赢,第一轮赌中了获得一分,后面每轮赌中得分翻倍,现在给出每两个队伍比赛的胜负概率,问你最大得分期望是多少。
整个比赛过程其实就是一颗完全二叉树,每一轮比赛对应二叉树的一层,每一场比赛对应二叉树的一个节点,
设 w[i][j] := 第i场比赛j队伍赢的概率,e[i][j] := 第i场比赛猜j队伍赢的总得分期望
i按照二叉树的结点编号来算
然后dfs过程中维护这两个数组就行了。
代码:
#include<bits/stdc++.h>#define ll long long#define inf 0x3f3f3f3f#define lson rt << 1#define rson rt << 1 | 1using namespace std;const int MAXN = 100010;double p[100][100];double w[500][100];// w[i][j] := 第i场比赛j队伍赢的概率 double e[500][100];//e[i][j] := 猜第i场比赛j队伍赢的得分期望 void dfs(int score, int l, int r, int rt){if(l == r){w[rt][l] = 1;e[rt][l] = score;return ; }int mid = (l + r) >> 1;dfs(score / 2, l, mid, lson);dfs(score / 2, mid + 1, r, rson);for(int i = l; i <= mid; i++)for(int j = mid + 1; j <= r; j++)w[rt][i] += w[lson][i] * w[rson][j] * p[i][j];for(int i = mid + 1; i <= r; i++)for(int j = l; j <= mid; j++)w[rt][i] += w[rson][i] * w[lson][j] * p[i][j];for(int i = l; i <= mid; i++)for(int j = mid + 1; j <= r; j++)e[rt][i] = max(e[rt][i], w[rt][i] * score + e[lson][i] + e[rson][j]);for(int i = mid + 1; i <= r; i++)for(int j = l; j <= mid; j++)e[rt][i] = max(e[rt][i], w[rt][i] * score + e[rson][i] + e[lson][j]);}int main(){int n, t;cin >> n;n = 1 << n;for(int i = 1; i <= n; i++){for(int j = 1; j <= n; j++)scanf("%d", &t), p[i][j] = 0.01 * t;}dfs(n / 2, 1, n, 1);printf("%.10lf", *max_element(e[1], e[1] + n + 1)); return 0;}
阅读全文
0 0
- codeforces~~~
- Codeforces
- codeforces
- Codeforces
- codeforces
- codeforces
- Codeforces
- Codeforces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- CodeForces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Codeforces
- Linux framebuffer显示bmp图片
- C#回顾学习笔记二十三:静态字段与递归
- Xcode报错 Compiling IB documents for earlier than iOS7 is no longer supported.
- 垂直居中的几种方式
- Mybatis查询oracle之clob类型
- CodeForces
- maven 与 nexus 中央仓库(私服) 发布与引用
- netty源码探索
- Unsupervised Learning Model-Reducing Dimension
- 比特币源码解析(16)
- react native Navigator使用踩的坑
- 集合扩容问题(ArrList为例,常用集合扩容机制) -- JAVA 基础
- 【LeetCode】2. Add Two Numbers
- jsp的常用的标签