CF708E Student's Camp

2022-09-19 14:16:12 浏览数 (1)

CF708E Student's Camp

题目链接:CF708E

有一个 (n 2) times m 的网格。

除了第一行和最后一行,其他每一行每一天最左边和最右边的格子都有 p 的概率消失。

k 天后,网格始终保持连通的概率。

n,m le 1.5 times 10^3k le 10^5,答案对 10^9 7 取模。

Tutorial

的格子的概率,有:

f_{i,l,r} = p_{l,r} sum_{l_p,r_p} f_{i-1,l_p,r_p} [[l_p,r_p]cap [l,r] not = emptyset]

其中 的概率,有:

begin{align}&p_{l,r} = P_{l-1}P_{m-r}\&P_{i}=binom ki p^i(1-p)^{k-i}end{align}

表示各个前缀和,即:

begin{align}&Fl_{i,l}=sum_{rge l} f_{i,l,r}\&Fr_{i,r}=sum_{lleq r} f_{i,l,r}\&Sl_{i,L}=sum_{l,rge L} f_{i,l,r} = sum_{lge L} Fl_{i,l}\&Sr_{i,R}=sum_{l,rleq R} f_{i,l,r}=sum_{rleq R} Fr_{i,r}end{align}
Fl_{i,j}=Fr_{i,m 1-j}\Sl_{i,j}=Sr_{i,m 1-j}

考虑转移 :

begin{align}Fr_{i,r}& =sum_{lleq r} p_{l,r}sum_{l_p,r_p}f_{i-1,l_p,r_p}\& = sum_{lleq r} p_{l,r} (Sr_{i-1,m}-Sr_{i-1,l-1}-Sl_{i-1,r 1})\& = sum_{lleq} P_{l-1}P_{m-r}(Sr_{i-1,m}-Sr_{i-1,l-1}-Sr_{i-1,m-r})\& = P_{m-r} ((Sr_{i-1,m}-Sr_{i-1,m-r})sum_{lleq r}P_{l-1})-P_{m-r}sum_{lleq r}P_{l-1}Sr_{i-1,l-1}end{align}

Solution

代码语言:javascript复制
#include<bits/stdc  .h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define W while
#define I inline
#define RI register int
#define LL long long
#define Cn const
#define CI Cn int&
#define gc getchar
#define D isdigit(c=gc())
#define pc(c) putchar((c))
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
using namespace std;
namespace Debug{
    Tp I void _debug(Cn char* f,Ty t){cerr<<f<<'='<<t<<endl;}
    Ts I void _debug(Cn char* f,Ty x,Ar... y){W(*f!=',') cerr<<*f  ;cerr<<'='<<x<<",";_debug(f 1,y...);}
    Tp ostream& operator<<(ostream& os,Cn vector<Ty>& V){os<<"[";for(Cn auto& vv:V) os<<vv<<",";os<<"]";return os;}
    #define gdb(...) _debug(#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
namespace FastIO{
    Tp I void read(Ty& x){char c;int f=1;x=0;W(!D) f=c^'-'?1:-1;W(x=(x<<3) (x<<1) (c&15),D);x*=f;}
    Ts I void read(Ty& x,Ar&... y){read(x),read(y...);}
    Tp I void write(Ty x){x<0&&(pc('-'),x=-x,0),x<10?(pc(x '0'),0):(write(x/10),pc(x '0'),0);}
    Tp I void writeln(Cn Ty& x){write(x),pc('n');}
}using namespace FastIO;
Cn int N=1.5e3 10,X=1e9 7,K=1e5 10;
int n,m,p,k,P[N],fac[K],ifac[K],G[N],Sr[N][N],Fr[N][N],H[N];
I int QP(RI a,RI b){RI s=1;W(b) b&1&&(s=1LL*s*a%X),a=1LL*a*a%X,b>>=1;return s;}
I int C(CI n,CI m){return 1LL*fac[n]*ifac[m]%X*ifac[n-m]%X;}
int main(){
    RI i,j,x,y;for(read(n,m,x,y,k),p=1LL*x*QP(y,X-2)%X,fac[0]=i=1;i<=k;i  ) fac[i]=1LL*fac[i-1]*i%X;
    for(ifac[k]=QP(fac[k],X-2),i=k-1;~i;i--) ifac[i]=1LL*ifac[i 1]*(i 1)%X;
    for(i=0;i<=min(m,k);i  ) P[i]=1LL*C(k,i)*QP(p,i)%X*QP(1-p,k-i)%X;
    for(i=1;i<=m;i  ) G[i]=(G[i-1] P[i-1])%X;
    for(Fr[0][m]=Sr[0][m]=1,i=1;i<=n;i  ){
        for(j=1;j<=m;j  ) H[j]=(H[j-1] 1LL*P[j-1]*Sr[i-1][j-1]%X)%X;
        for(j=1;j<=m;j  ) Fr[i][j]=(1LL*P[m-j]*(Sr[i-1][m]-Sr[i-1][m-j])%X*G[j]%X-1LL*P[m-j]*H[j]%X)%X;
        for(j=1;j<=m;j  ) Sr[i][j]=(Sr[i][j-1] Fr[i][j])%X;
    }return writeln((Sr[n][m] X)%X),0;
}
amp

0 人点赞