Crossword Expert CodeForces - 1194F (期望)
大意: $n$个题, 按照第$i$题随机$t_i$或$t_i+1$秒钟完成, 最多做$T$秒, 求做题数期望.
期望转为做题数$\ge x$的方案数之和最后再除以总方案数
这是因为$\sum\limits_{x}x{cnt}_x=\sum\limits_{x}\sum\limits_{y\ge x}{cnt}_y$
然后得到对于$x$的贡献为$2^{n-x}\sum\limits_{k=0}^{min(x,T-s[x])}\binom{x}{k}$
上面的和式中$k$最大值关于$x$是递减的, 可以逆序枚举$x$, $O(1)$将$\sum\binom{x+1}{k}$转移到$\sum\binom{x}{k}$.
复杂度就为$O(n)$.
#include <iostream>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
using namespace std;
typedef long long ll;
const int P = 1e9+7, inv2 = (P+1)/2;
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
const int N = 1e6+10;
int n,a[N],fac[N],ifac[N],po[N];
ll T,s[N];
int C(ll n, ll m) {
if (n<m) return 0;
return (ll)fac[n]*ifac[m]%P*ifac[n-m]%P;
} int main() {
fac[0]=ifac[0]=po[0]=1;
REP(i,1,N-1) po[i]=po[i-1]*2ll%P;
REP(i,1,N-1) fac[i]=(ll)fac[i-1]*i%P;
ifac[N-1]=inv(fac[N-1]);
PER(i,1,N-2) ifac[i]=(ll)ifac[i+1]*(i+1)%P;
scanf("%d%lld", &n, &T);
REP(i,1,n) scanf("%d",a+i),s[i]=s[i-1]+a[i];
int ans = 0, ret = 0, pre = -1;
PER(i,1,n) if (s[i]<=T) {
int mx = i;
if (T-s[i]<mx) mx = T-s[i];
if (!mx) ret = 1;
else if (pre>mx) ret = po[i];
else {
REP(j,pre+1,mx) ret = (ret+C(i+1,j))%P;
ret = (ret+C(i,mx))*(ll)inv2%P;
}
ans = (ans+(ll)ret*po[n-i])%P;
pre = mx;
}
ans = (ll)ans*inv(po[n])%P;
if (ans<0) ans += P;
printf("%d\n", ans);
}
Crossword Expert CodeForces - 1194F (期望)的更多相关文章
- Codeforces 1194F. Crossword Expert
传送门 考虑每一个位置的期望贡献 $P[i]$ 对于第 $k$ 个位置,设 $sum=\sum_{i=1}^{k}t[k]$,那么 $T-sum$ 即为用最短时间完成完位置 $k$ 后多出来的空闲时间 ...
- Codeforces - 1194F - Crossword Expert - 组合数学
https://codeforc.es/contest/1194/problem/F 下面是错的. 看起来有点概率dp的感觉? 给你T秒钟时间,你要按顺序处理总共n个事件,每个事件处理花费的时间是ti ...
- 【CF1194F】Crossword Expert(数学 期望)
题目链接 大意 给你\(N\)个事件,解决每个事件所需的时间有\(1/2\)的概率为\(t[i]\),\(1/2\)的概率为\((t[i]+1)\),给你总时间\(T\),在\(T\)时间内按顺序解决 ...
- codeforces 1194F (组合数学)
Codeforces 11194F (组合数学) 传送门:https://codeforces.com/contest/1194/problem/F 题意: 你有n个事件,你需要按照1~n的顺序完成这 ...
- Intergalaxy Trips CodeForces - 605E (期望,dijkstra)
大意: 给定矩阵$p$, $p_{i,j}$表示每一秒点$i$到点$j$有一条边的概率, 每秒钟可以走一条边, 或者停留在原地, 求最优决策下从$1$到$n$的期望用时. $f_x$为从$x$到$n$ ...
- CF1194F Crossword Expert(数论,组合数学)
不难的一题.不知道为什么能 $2500$…… 不过场上推错了一直不会优化…… 首先考虑 $f_i$ 表示恰好做完前 $i$ 道题的概率. 这样很难算.修改一下,$f_i$ 表示做完至少 $i$ 道题的 ...
- Codeforces 123E Maze(树形DP+期望)
[题目链接] http://codeforces.com/problemset/problem/123/E [题目大意] 给出一棵,给出从每个点出发的概率和以每个点为终点的概率,求出每次按照dfs序从 ...
- Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案
You're trying to set the record on your favorite video game. The game consists of N levels, which mu ...
- Codeforces 839C Journey - 树形动态规划 - 数学期望
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can r ...
随机推荐
- unittest 的用法
一.discover方法 discover方法可以根据标准加载用例,并将结果返回给测试套件(suite),start_dir:待测试的目录,pattern:测试用例文件名的匹配规. 如: start_ ...
- Linux Bash Shell j简单入门
BASH 的基本语法 最简单的例子 —— Hello World! 关于输入.输出和错误输出 BASH 中对变量的规定(与 C 语言的异同) BASH 中的基本流程控制语法 函数的使用 2.1 ...
- WebDriver介绍
Fetching a Page driver.get("http://www.google.com") Locating UI Elements (WebElements) By ...
- 【已解决】HttpWebRequest的GetResponse或GetRequestStream偶尔超时 + 总结各种超时死掉的可能和相应的解决办法
[问题] 用C#模拟网页登陆,其中去请求几个页面,会发起对应的http的请求request,其中keepAlive设置为true,提交请求后,然后会有对应的response: resp = (Http ...
- 第一个php文件运行
运行会发现报错,解决参考:写的很详细 http://blog.csdn.net/meegomeego/article/details/36020553
- Node.js使用child_process调用系统命令示例
首先我们在D盘根目录下新建一个test.bat文件,他的内容如下: echo %date%%time% >> D:/test.txt 他的目的很简单,每次调用这个bat文件,都会在D:/t ...
- PostgreSQL学习笔记——摘要
因为PostgreSQL和MySQL.DB2等数据库均遵循SQL语法,所以这篇随笔仅记录一些PostgreSQL中和别的数据库有差别或之前学习中遗漏的地方,以及一些我觉得比较重点的地方. 通过psql ...
- python的jenkins三方包
jenkinsapi 比较重,实现不好 python-jenkins 比较轻,建议使用,可以进行二次开发和封装
- 异地协作,A地上传jar包到B地服务器上传速率慢
在A地使用ftp服务器,再登录B地的目标服务器,使用ftp命令从ftp服务器下载文件,速度快点,下载带宽比上传带宽要大一点 https://blog.csdn.net/df0128/article/d ...
- Ext.jsTree 向子节点添加叶子节点
// 定义搜索节点树结构Store const nodeStore = Ext.create('Ext.data.TreeStore', { autoLoad : true, id : 'nodeSt ...