题目链接

完整比赛在这儿

杜老师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. C# 无法识别的消息版本。

    问题:最近跟OA的java项目做审核接口,调用接口时提示"无法识别的消息版本.“ 解决:一直以为是协议不兼容,查了半天,最终发现是这个项目.net framework版本太低,升级为高版本即 ...

  2. ubuntu16.04安装opencv2.4.13

    1.更新 sudo apt-get update sudo apt-get upgrade 2.安装关联库 2.1 搭建C/C++编译环境 sudo apt-get install build-ess ...

  3. 嵌入式Linux驱动笔记(十八)------浅析V4L2框架之ioctl【转】

    转自:https://blog.csdn.net/Guet_Kite/article/details/78574781 权声明:本文为 风筝 博主原创文章,未经博主允许不得转载!!!!!!谢谢合作 h ...

  4. Qt Ubuntu 编译出错-1: error: 找不到 -lGL

    安装好,编译界面程序出错“-1: error: 找不到 -lGL” 在终端运行如下命令(安装Qt5.8.0) sudo apt-get install libqt5-dev sudo apt-get ...

  5. python 运行日志logging代替方案

    以下是自己写的 记录日志的代码.(和logging不搭嘎,如果如要学loggging模块,本文末尾有他人的链接.) # prtlog.py ############################## ...

  6. C#中Convert.ToInt32、int.TryParse、(int)和int.Parse四者的区别

    Convert.ToInt32.(int)和int.Parse三者的区别: 首先:Convert.ToInt32 适合将object类类型转换成int类型,如Convert.ToInt32(sessi ...

  7. keras2.0的一些变化

    keras 变化太快了https://github.com/fchollet/keras/wiki/Keras-2.0-release-notes

  8. 并发之atomicInteger与CAS机制

    并发之atomic与CAS自旋锁 通过前几章的讲解我们知道i++这种类似操作是不安全的.针对这种情况,我们可能会想到利用synchronize关键字实现线程同步,保证++操作的原子性,的确这是一种有效 ...

  9. [PHP] 链表数据结构(单链表)

    链表:是一个有序的列表,但是它在内存中是分散存储的,使用链表可以解决类似约瑟夫问题,排序问题,搜索问题,广义表 单向链表,双向链表,环形链表 PHP的底层是C,当一个程序运行时,内存分成五个区(堆区, ...

  10. 目标检测-yolo2

    转载自:http://blog.csdn.net/qq_34784753/article/details/78825493 对于现在的最好的检测系统来说,yolo_v1 的问题主要出现在两方面,也就是 ...