传送门

考虑每一个位置的期望贡献 $P[i]$

对于第 $k$ 个位置,设 $sum=\sum_{i=1}^{k}t[k]$,那么 $T-sum$ 即为用最短时间完成完位置 $k$ 后多出来的空闲时间

如果 $T-sum>=k$ 那么这个位置一定能完成,贡献为 $1$

如果 $T<sum$ ,那么这个位置一定没法完成,贡献为 $0$

否则设 $mx=max(T-sum,k)$,那么这个位置完成的总情况数就是在多出来的时间内任选几个位置多花费 $1$

那么这个位置有 $\sum_{i=0}^{mx} \binom {mx}{i} $ 种不同的合法方案,再除以总方案数 $2^k$ 即为概率

因为价值为 $1$,那么期望贡献 $P[i]$ 就是 $\frac {1} {2^k} \sum_{i=0}^{mx} \binom {mx}{i} $

然后发现直接计算一堆组合数的复杂度是 $n^2$ 的,考虑如何优化计算过程

注意到我们每次算组合数时的 $\binom {mx} {i} $ 的 $mx$ 是单调递减的(显然只要考虑 $T-sum<k$ 时的情况),并且每次 $i$ 加一

考虑杨辉三角递推组合数时,$2\sum_{j=0}^{x}\binom {i}{j}=(\sum_{j=0}^{x}\binom {i+1}{j})+\binom {i}{x}$(这个自己画一下杨辉三角就知道了)

那么我们就可以动态维护 $now=\sum_{i=0}^{mx} \binom {mx}{i}$,然后每到下一层就 $now=now*2-\binom {i-1}{mx_{i-1}}$

然后再利用 $mx$ 的单调性直接暴力维护一下 $now$ 即可做到 $O(n)$

然后就过了,注意 $long\ long$

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long ll;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(ch<''||ch>'') { if(ch=='-') f=-; ch=getchar(); }
while(ch>=''&&ch<='') { x=(x<<)+(x<<)+(ch^); ch=getchar(); }
return x*f;
}
const int N=4e5+,mo=1e9+;
inline int fk(int x) { return x>=mo ? x-mo : x; }
int n,t[N],fac[N],finv[N],ans;
ll T;
inline int ksm(int x,int y)
{
int res=;
while(y) { if(y&) res=1ll*res*x%mo; x=1ll*x*x%mo; y>>=; }
return res;
}
inline int C(int x,int y) { return 1ll*fac[x]*finv[y]%mo*finv[x-y]%mo; }
int main()
{
n=read(); T=read();
fac[]=; finv[]=;
for(int i=;i<=n;i++)
{
t[i]=read();
fac[i]=1ll*fac[i-]*i%mo;
finv[i]=ksm(fac[i],mo-);
}
int i2=,now=,pre=; ll sum=;
for(int i=;i<=n;i++)
{
sum+=t[i]; i2=fk(i2+i2);
if(T-sum>=i) { ans++; continue; }
if(T-sum<) break;
int mx=T-sum;
if(!now)
{
for(int j=;j<=mx;j++) now=fk(now+C(i,j));
pre=mx; ans=fk(ans+1ll*now*ksm(i2,mo-)%mo);
continue;
}
now=fk( fk(now+now)-C(i-,pre)+mo );
while(pre>mx) now=fk(now-C(i,pre)+mo),pre--;
ans=fk(ans+1ll*now*ksm(i2,mo-)%mo);
}
printf("%d\n",ans);
return ;
}

Codeforces 1194F. Crossword Expert的更多相关文章

  1. Codeforces - 1194F - Crossword Expert - 组合数学

    https://codeforc.es/contest/1194/problem/F 下面是错的. 看起来有点概率dp的感觉? 给你T秒钟时间,你要按顺序处理总共n个事件,每个事件处理花费的时间是ti ...

  2. Crossword Expert CodeForces - 1194F (期望)

    大意: $n$个题, 按照第$i$题随机$t_i$或$t_i+1$秒钟完成, 最多做$T$秒, 求做题数期望. 期望转为做题数$\ge x$的方案数之和最后再除以总方案数 这是因为$\sum\limi ...

  3. Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]

    题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...

  4. codeforces 1194F (组合数学)

    Codeforces 11194F (组合数学) 传送门:https://codeforces.com/contest/1194/problem/F 题意: 你有n个事件,你需要按照1~n的顺序完成这 ...

  5. CF1194F Crossword Expert(数论,组合数学)

    不难的一题.不知道为什么能 $2500$…… 不过场上推错了一直不会优化…… 首先考虑 $f_i$ 表示恰好做完前 $i$ 道题的概率. 这样很难算.修改一下,$f_i$ 表示做完至少 $i$ 道题的 ...

  6. 【CF1194F】Crossword Expert(数学 期望)

    题目链接 大意 给你\(N\)个事件,解决每个事件所需的时间有\(1/2\)的概率为\(t[i]\),\(1/2\)的概率为\((t[i]+1)\),给你总时间\(T\),在\(T\)时间内按顺序解决 ...

  7. Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crossword —— 基础题

    题目链接:http://codeforces.com/contest/721/problem/A A. One-dimensional Japanese Crossword time limit pe ...

  8. Codeforces Round #422 (Div. 2) B. Crossword solving 枚举

    B. Crossword solving     Erelong Leha was bored by calculating of the greatest common divisor of two ...

  9. 【Codeforces Round #422 (Div. 2) B】Crossword solving

    [题目链接]:http://codeforces.com/contest/822/problem/B [题意] 让你用s去匹配t,问你最少需要修改s中的多少个字符; 才能在t中匹配到s; [题解] O ...

随机推荐

  1. HNOI2012排队

    排列组合题(本文A(n,m)表示从n个元素里选m个的排列数). 首先,老师和女生有不能相邻的限制条件,应该用插空法.而且老师人数较少且固定,把老师和男生进行混合,对女生用插空. 我先来一手错误做法,n ...

  2. Nginx-rtmp之 AMF0 的处理

    1. 综述 当检测到接收到的 RTMP 消息中 Message Header 中 message type id 为 20 时,表示,接收到的是 AMF 类型的数据, 因此需要对接收的数据进行 AMF ...

  3. FastAdmin 添加新字段后,不显示,可以直接去修改对应的js

  4. koa 项目实战(四)注册接口和调试工具(postman)

    1.安装模块 npm install koa-bodyparser --save npm install bcryptjs --save 2.引入模块 根目录/app.js const bodyPar ...

  5. ios修改UIIMage大小

    /** * 改变图片的大小 * * @param img 需要改变的图片 * @param newsize 新图片的大小 * * @return 返回修改后的新图片 */ - (UIImage *)s ...

  6. 【原】vue-router中params和query的区别

    1.引入方式不同 query要用path来引入 this.$router.push({ path: 'test', query: { type: 2, detail: '哈哈' } }) params ...

  7. append和push和pop区别

    append()    操作的是DOM节点,在被选元素的结尾(内部结尾)插入指定内容: push()        向数组末尾插入一个或者多个元素,并且返回新的长度: pop()         删除 ...

  8. 数据解析框架之FastJson

    演示实体类 import java.util.List; public class Student { public String name; public int age; public List& ...

  9. 美化Eclipse-背景

    为了美化Eclipse,请登录主题网站http://www.eclipsecolorthemes.org/ 下载EPF配置文件(截图如下),并导入eclispe即可. 导入方法: (1)从File菜单 ...

  10. ajax post 请求

    $(".login_btn").click(function(){ if($(".user_").val()=="admin"&&a ...