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 ...
随机推荐
- 深入理解JVM虚拟机7:JNDI,OSGI,Tomcat类加载器实现
打破双亲委派模型 JNDI JNDI 的理解 JNDI是 Java 命名与文件夹接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之中的一 ...
- SpringCloud介绍及入门一
springcloud是什么 基于spring boot实现的服务治理工具包,管理和协微服务 把别人的东西拿来组合在一起,形成各种组件 微服务协调者[service registtry注册中心 Eur ...
- docker启动elasticsearch失败--jvm内存不足解决方案
centos下载完elasticsearch并修改完配置后运行docker命令: docker run –name es1 -p : -p : -d -v /docker/es/esmaster/es ...
- Pandas的Categorical Data
http://liao.cpython.org/pandas15/ Docs » Pandas的Categorical Data类型 15. Pandas的Categorical Data panda ...
- Redis操作类型
- LC 991. Broken Calculator
On a broken calculator that has a number showing on its display, we can perform two operations: Doub ...
- android.support.design库的引用和冲突解决
android.support.design库的引用和冲突解决 转 https://www.jianshu.com/p/2a0a2af9f2b4 最近在工程中使用到android.support.de ...
- Ionic4.x Javascript 扩展 ActionSheet Alert Toast Loading 以及 ionic 手势相 关事件
1.ActionSheet 官方文档:https://ionicframework.com/docs/api/action-sheet <ion-header> <ion-toolb ...
- 简介Python中用于处理字符串的center()方法
简介Python中用于处理字符串的center()方法 这篇文章主要介绍了简介Python中用于处理字符串的center()方法,是Python入门中的基础知识,需要的朋友可以参考下 center() ...
- WCAG
WCAG What is WCAG? Web Content Accessibility Guidelines (WCAG) Overview Checklist and solve technolo ...