Codeforces Round #333 E. Kleofáš and the n-thlon (期望dp)
来源:互联网 发布:usleep 源码 编辑:程序博客网 时间:2024/05/17 06:09
题意:
有n<=100场比赛,每场比赛有m<=1000个人参加,每场比赛都会排名次,得分即为名次
比赛比完了,某个人只记得自己的名次,其他的人不记得,求出这个人排名的期望值
分析:
−−思路很奇妙,我们肯定不能直接求排名的概率或者期望,换个思路反向想一下,我们可以求得分的人数的期望
考虑f[i][j]:=进行了i场比赛,其他人得分为j的人的期望个数,不算自己的话好求答案
f[0][0]=m−1
由于一场比赛可以得到1−m的分,所以f[i][j]=∑f[i][k],k∈[j−1,j−m]
多算了自己,要把自己减去,f[i][j]=f[i][j]−f[i][j−a[i]]
嘛−−区间求和可以用partial sum简单来做.BIT或者维护前缀和都是可以的
这样就可以在O(n∗nm∗1)或者O(n∗nm∗log(nm))来求解了
代码:
不知道为啥没RE - - 明明数组开小了, 这里用partial sum转移的
//// Created by TaoSama on 2015-11-29// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, m, a[N];double f[2][N];int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); while(scanf("%d%d", &n, &m) == 2) { int sum = 0; for(int i = 1; i <= n; ++i) { scanf("%d", a + i); sum += a[i]; } if(m == 1) {puts("1"); continue;} int cur = 0, nxt = 1; memset(f[cur], 0, sizeof f[cur]); f[cur][0] = m - 1; for(int i = 0; i < n; ++i) { memset(f[nxt], 0, sizeof f[nxt]); for(int j = 0; j <= i * m; ++j) { double p = f[cur][j] / (m - 1); f[nxt][j + 1] += p; f[nxt][j + m + 1] -= p; f[nxt][j + a[i + 1]] -= p; f[nxt][j + a[i + 1] + 1] += p; } for(int j = 1; j <= n * m; ++j) f[nxt][j + 1] += f[nxt][j]; swap(cur, nxt); } double ans = 0; for(int i = 0; i < sum; ++i) ans += f[cur][i]; printf("%.12f\n", ans + 1); } return 0;}
0 0
- Codeforces Round #333 E. Kleofáš and the n-thlon (期望dp)
- Codeforces Round #333 (Div. 2) E. Kleofáš and the n-thlon (概率dp)
- 【codeforces 602E】Kleofáš and the n-thlon
- 【Codeforces Round 333 (Div 2)E】【期望DP概率做法 树状数组转前缀和】Kleofáš and the n-thlon n场比赛m个人获得总名次的期望
- codeforces 602 E. Kleofáš and the n-thlon (概率dp)
- Codeforces 601C Kleofáš and the n-thlon(dp)
- CodeForces 601 C.Kleofáš and the n-thlon(概率DP)
- CF 601C(Kleofáš and the n-thlon-期望dp)
- 【Codeforces Round 333 (Div 2)E 期望DP概率
- [Codeforces 673E] Levels and Regions (期望+斜率DP)
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph【DP】
- Codeforces Round #261 (Div. 2) E. Pashmak and Graph DP
- Codeforces Round #316 (Div. 2) E. Pig and Palindromes DP
- Codeforces Round #316 (Div. 2) E. Pig and Palindromes (DP)
- Codeforces Round #316 (Div. 2) E. Pig and Palindromes dp
- codeforces 16E Fish (概率-期望DP)
- 【Codeforces Round 275 (Div 2)E】【状压DP 概率DP求期望 线性相加思想 二进制系统函数】Game with Strings n个串目标串随机猜位置随机的猜出答案的期望步
- DP训练 Codeforces 673E Levels and Regions [斜率优化dp][期望]
- 【C#】简单工厂模式
- SQL总结(七)查询实战
- ubuntu关闭cups服务(631端口)
- 支付宝PHP-RSA公钥和私钥的生成
- bootstrap datetimepicker定位不准确问题
- Codeforces Round #333 E. Kleofáš and the n-thlon (期望dp)
- 数字签名是什么
- ajax异步请求php后台处理耗时任务session_write_close
- SSH原理与运用
- Codeforces Round #333 D. Lipshitz Sequence (单调栈)
- 我使用过的Linux命令之tee - 重定向输出到多个文件
- [宇宙与天文]平行宇宙与时空转移
- pyzmq的4种模式(PUB/SUB)笔记
- ajaxfileupload多文件上传