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 ...
随机推荐
- 2018-2019-2 网络对抗技术 20165222 Exp 8 Web基础
1.实践内容 (1).Web前端HTML 能正常安装.启停Apache.理解HTML,理解表单,理解GET与POST方法,编写一个含有表单的HTML. 使用service apache2 start启 ...
- IO流——常用IO流详解
1:字节流 字节流:用于处理以字节为单位的二进制文件(如音乐,图片等) InputStream 是抽象类 它的对应子类FileInputStream可以被实例化 构造方法: FileInputStre ...
- How can I get a Netty server to reload a TLS certificate when it is renewed?
java - How can I get a Netty server to reload a TLS certificate when it is renewed? - Stack Overflow ...
- VMware vSphere Client中启动虚拟机提示No boot filename received/Operating System not found解决方法
昨天下载安装 .NET Framework 3.5 SP1解决了VMware vSphere Client安装问题后,今天需要远程连接服务器搭建一台虚拟机. 根据指引步骤进行下一步.下一步的操作完成后 ...
- angular父组件通过@ViewChild 主动获取子组 件的数据和方法
1.调用子组件给子组件定义一个名称 <app-footer #footerChild></app-footer> 2. 引入 ViewChild import { Compon ...
- mysql占用服务器cpu过高的原因以及解决办法
登陆Mysql: mysql -p<port> -u<user> -p<pwd> mysql> show processlist; show processl ...
- Core Data 的线程安全问题
前言: 很多小的App只需要一个ManagedContext在主线程就可以了,但是有时候对于CoreData的操作要耗时很久的,比如App开启的时候要载入大量数据,如果都放在主线程,毫无疑问会阻塞UI ...
- Intellij IDEA 2016.3.4 注册激活--转
对于Intellij IDEA 2016.3.4 可以填写注册server http://jetbrains.tech 来激活. 参考:https://www.haxotron.com/jetbra ...
- iOS-MPMoviePlayerViewController使用
其实MPMoviePlayerController如果不作为嵌入视频来播放(例如在新闻中嵌入一个视频),通常在播放时都是占满一个屏幕的,特别是在 iPhone.iTouch上.因此从iOS3.2以后苹 ...
- CEIWEI CommMonitor 串口监控精灵11.0 SDK/OCX 串口过滤驱动
CommMonitorX 监视精灵SDK,能够嵌入到你的App程序中,从而在你的App中实现串行端口分析.调试串行设备的协议信息,并可以拦截.记录串行端口程序操作串口的TX.Rx数据包.串口置信息如波 ...