题目链接

完整比赛在这儿

杜老师tql

求期望要抽卡的次数,也就是求期望经历了多少不满足状态。而每个不满足的状态对答案的贡献为\(1\),所以可以直接算概率。即\(Ans=\sum_{不满足状态s} P(s)\)。

设有\(x_i\)个\(i\),其贡献为\(s_i\)。

当\(x_i>c_i\)时,\(s_i=c_i+\frac{x_i-c_i}{4}\);

当\(x_i\leq c_i\)时,\(s_i=x_i-c_i\)。

若\(\sum s_i<0\),则是不满足状态,此时\(P=p_1^{x_1}p_2^{x_2}...p_n^{x_n}\frac{(x_1+x_2+...+x_n)!}{x_1!x_2!...x_n!}\)。

令\(f[i][j][k]\)表示当前考虑到第\(i\)种元素,贡献和为\(j\),总共选了\(k\)个的概率。

转移直接枚举\(x_i\),乘上个系数\(\frac{p_i^{x_i}}{x_i!}\)。最后\(Ans=ans\times k!\)。

\(i\)是\(10\),\(j\)最大是\(400*2\),\(k\)是\(1600\),转移\(O(1600)\),还是能过的。。吧。。

有点卡不过去。。加上强大的取模优化可以卡到\(90\)。

我们只关心不满足的状态,所以中间满足条件了的状态可以不要。令\(f[i][j][k]\)的\(j\)表示还需\(j\)的贡献才能满足条件。那么初始化\(f[0][\sum c_i][0]=1\),转移时小于等于\(0\)的\(j'\)可以忽略,且\(j\)的上限只需要\(400\)。

这样就可以轻松过了。


//7460ms	50648kb
#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define mod 1000000007
#define Inv(x) FP(x,mod-2)
#define Add(x,v) (x+=v)>=LIM&&(x%=mod)
typedef long long LL;
const int N=12,M=1603;
const LL LIM=6e18; int q[N],p[N],c[N],fac[M],ifac[M],coef[M]/*coefficient*/;
LL f[N][M][405]; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int FP(int x,int k)
{
int t=1;
for(; k; k>>=1,x=1ll*x*x%mod)
if(k&1) t=1ll*t*x%mod;
return t;
} int main()
{
int n=read(),s=0;
for(int i=1; i<=n; ++i) s+=q[i]=read();
int inv=Inv(s); s=0;
for(int i=1; i<=n; ++i) p[i]=1ll*q[i]*inv%mod, s+=c[i]=read(); const int lim=s<<2;
fac[0]=fac[1]=1;
for(int i=2; i<=lim; ++i) fac[i]=1ll*fac[i-1]*i%mod;
ifac[lim]=Inv(fac[lim]);
for(int i=lim; i; --i) ifac[i-1]=1ll*ifac[i]*i%mod; const int sum=s;
f[0][0][sum]=1;
for(int i=0; i<n; ++i)
{
LL pw=p[i+1]; coef[0]=1;
for(int j=1,pi=pw; j<=lim; ++j) coef[j]=pw*ifac[j]%mod, pw=pw*pi%mod; int cost=c[i+1]; LL v;
for(int j=0; j<=lim-3; ++j)//f[i][j][k]:选j个 所需贡献为k
for(int k=0; k<=sum; ++k)
if((v=f[i][j][k]%mod))
for(int l=0; l+j<=lim; ++l)
{
int tmp=(l<=cost?l-cost:l-cost>>2)+cost;
if(tmp>=k) break;
Add(f[i+1][l+j][k-tmp],v*coef[l]);
}
}
LL ans=1;//0
for(int i=1; i<=lim; ++i)
{
LL tmp=0;
for(int j=1; j<=sum; ++j) tmp+=f[n][i][j]%mod;
ans+=tmp%mod*fac[i]%mod;
}
printf("%lld\n",ans%mod); return 0;
}

90分代码:

#include <cstdio>
#include <cctype>
#include <algorithm>
#define gc() getchar()
#define D 402
#define mod 1000000007
#define Inv(x) FP(x,mod-2)
#define Add(x,v) (x+=v)>=LIM&&(x%=mod)
typedef long long LL;
const int N=12,M=1603;
const LL LIM=6e18; int q[N],p[N],c[N],fac[M],ifac[M],coef[M]/*coefficient*/;
LL f[N][M][805]; inline int read()
{
int now=0;register char c=gc();
for(;!isdigit(c);c=gc());
for(;isdigit(c);now=now*10+c-'0',c=gc());
return now;
}
inline int FP(int x,int k)
{
int t=1;
for(; k; k>>=1,x=1ll*x*x%mod)
if(k&1) t=1ll*t*x%mod;
return t;
} int main()
{
int n=read(),s=0;
for(int i=1; i<=n; ++i) s+=q[i]=read();
int inv=Inv(s); s=0;
for(int i=1; i<=n; ++i) p[i]=1ll*q[i]*inv%mod, s+=c[i]=read(); const int lim=s<<2;
fac[0]=fac[1]=1;
for(int i=2; i<=lim; ++i) fac[i]=1ll*fac[i-1]*i%mod;
ifac[lim]=Inv(fac[lim]);
for(int i=lim; i; --i) ifac[i-1]=1ll*ifac[i]*i%mod; f[0][0][D]=1;
const int sum=s,R=D+sum;
for(int i=0,s=0; i<n; s+=c[++i])
{
LL pw=p[i+1]; coef[0]=1;
for(int j=1,pi=pw; j<=lim; ++j) coef[j]=pw*ifac[j]%mod, pw=pw*pi%mod; int cost=c[i+1]; LL v;
for(int j=0,L=D-s; j<=lim-3; ++j)//f[i][j][k]:选j个 贡献为k
for(int k=L; k<=R; ++k)
if((v=f[i][j][k]%mod))
for(int l=0; l+j<=lim; ++l)
{
int tmp=k+(l<=cost?l-cost:l-cost>>2);
if(tmp>D+sum) break;
Add(f[i+1][l+j][tmp],v*coef[l]);
}
}
LL ans=0;
for(int i=0; i<lim; ++i)
{
LL sum=0;
for(int j=0; j<D; ++j) sum+=f[n][i][j]%mod;
ans+=sum%mod*fac[i]%mod;
}
printf("%lld\n",ans%mod); return 0;
}

8.9 正睿暑期集训营 Day6 C 风花雪月(DP)的更多相关文章

  1. 8.9 正睿暑期集训营 Day6

    目录 2018.8.9 正睿暑期集训营 Day6 A 萌新拆塔(状压DP) B 奇迹暖暖 C 风花雪月(DP) 考试代码 A B C 2018.8.9 正睿暑期集训营 Day6 时间:2.5h(实际) ...

  2. 8.6 正睿暑期集训营 Day3

    目录 2018.8.6 正睿暑期集训营 Day3 A 亵渎(DP) B 绕口令(KMP) C 最远点(LCT) 考试代码 A B C 2018.8.6 正睿暑期集训营 Day3 时间:5h(实际) 期 ...

  3. 8.10 正睿暑期集训营 Day7

    目录 2018.8.10 正睿暑期集训营 Day7 总结 A 花园(思路) B 归来(Tarjan 拓扑) C 机场(凸函数 点分治) 考试代码 A B C 2018.8.10 正睿暑期集训营 Day ...

  4. 8.8 正睿暑期集训营 Day5

    目录 2018.8.8 正睿暑期集训营 Day5 总结 A 友谊巨轮(线段树 动态开点) B 璀璨光滑 C 构解巨树 考试代码 A B C 2018.8.8 正睿暑期集训营 Day5 时间:3.5h( ...

  5. 8.7 正睿暑期集训营 Day4

    目录 2018.8.7 正睿暑期集训营 Day4 A 世界杯(贪心) B 数组(线段树) C 淘汰赛 考试代码 A B C 2018.8.7 正睿暑期集训营 Day4 时间:5h(实际) 期望得分:. ...

  6. 8.5 正睿暑期集训营 Day2

    目录 2018.8.5 正睿暑期集训营 Day2 总结 A.占领地区(前缀和) B.配对(组合) C 导数卷积(NTT) 考试代码 T1 T2 T3 2018.8.5 正睿暑期集训营 Day2 时间: ...

  7. 8.4 正睿暑期集训营 Day1

    目录 2018.8.4 正睿暑期集训营 Day1 A 数对子 B 逆序对 C 盖房子 考试代码 A B C 2018.8.4 正睿暑期集训营 Day1 时间:4.5h(实际) 期望得分:30+50+3 ...

  8. 7.30 正睿暑期集训营 A班训练赛

    目录 2018.7.30 正睿暑期集训营 A班训练赛 T1 A.蔡老板分果子(Hash) T2 B.蔡老板送外卖(并查集 最小生成树) T3 C.蔡老板学数学(DP NTT) 考试代码 T2 T3 2 ...

  9. 正睿OI集训游记

    什么嘛....就是去被虐的... 反正就是难受就是了.各种神仙知识点,神仙题目,各式各样的仙人掌..... 但是还是学会了不少东西...... 应该是OI生涯最后一次集训了吧.... 这次的感言还是好 ...

随机推荐

  1. 转载:(Mac)在bash和zsh配置环境变量path的几种方法

    参考文献 老习惯,列出本文参考或引用或转载的文档和博客,致以崇高的敬意,感兴趣的可以去看看 1.http://postgresapp.com/ 2.http://postgresapp.com/doc ...

  2. mysql 常用,使用经验

    mysql default  boolean字段 `enable` char(1) NOT NULL DEFAULT '1' COMMENT '启(禁)用',结果: this.enable ? &qu ...

  3. python中的zip、map、reduce 、lambda函数的使用。

    lambda只是一个表达式,函数体比def简单很多. lambda的主体是一个表达式,而不是一个代码块.仅仅能在lambda表达式中封装有限的逻辑进去. lambda表达式是起到一个函数速写的作用.允 ...

  4. python 全栈开发,Day68(Django的路由控制)

    昨日内容回顾 1 MVC和MTV MTV 路由控制层(分发哪一个路径由哪一个视图函数处理) V : views (逻辑处理) T : templates (存放html文件) M : model (与 ...

  5. python 全栈开发,Day55(jQuery的位置信息,JS的事件流的概念(重点),事件对象,jQuery的事件绑定和解绑,事件委托(事件代理))

    一.jQuery的位置信息 jQuery的位置信息跟JS的client系列.offset系列.scroll系列封装好的一些简便api. 一.宽度和高度 获取宽度 .width() 描述:为匹配的元素集 ...

  6. python 全栈开发,Day38(在python程序中的进程操作,multiprocess.Process模块)

    昨日内容回顾 操作系统纸带打孔计算机批处理 —— 磁带 联机 脱机多道操作系统 —— 极大的提高了CPU的利用率 在计算机中 可以有超过一个进程 进程遇到IO的时候 切换给另外的进程使用CPU 数据隔 ...

  7. HDU1730 Northcott Game 尼姆博弈

    Northcott Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  8. ElasticSearch - match vs term

    match vs term 这个问题来自stackoverflow https://stackoverflow.com/questions/23150670/elasticsearch-match-v ...

  9. IE下script标签的readyState属性

    在做加载器时遇到一个常见问题,如何判定一个脚本已经执行完毕. "uninitialized" – 原始状态 "loading" – 下载数据中 "lo ...

  10. 【AtCoder】全国統一プログラミング王決定戦予選/NIKKEI Programming Contest 2019

    感觉最近好颓,以后不能这么颓了,要省选了,争取省选之前再板刷一面ATC??? A - Subscribers 简单容斥 #include <bits/stdc++.h> #define f ...