Loading

【题解】牛客挑战赛 44 - 数列的和 [*medium]

吐槽:出题人比赛中途换这题,真的太 /tuu 了。


题目传送门

考虑令:

\[F(x)=\sum_{i\geq 0} (i^2+2ki)x^i \]

然后答案显然为:

\[ans=\sum_{i=n}^{m}(m-i)[x^i]F^n(x) \]

推式子:

\[\begin{aligned} F(x)&=\sum_{i\geq 0} (i^2+2ki)x^i\\ &=\sum_{i\geq 0} i^2x^i+\sum_{i\geq 0} 2kix^i\\ &=\frac{x(1+x)}{(1-x)^3}+\frac{2kx}{(1-x)^2}\\ &=\frac{x(1+x)+(1-x)2kx}{(1-x)^3}\\ &=\frac{x((1+2k)+(1-2k)x)}{(1-x)^3}\\ \end{aligned} \]

考虑令:

\[G(x)=\sum_{i\geq 0} ix^i=\frac{x}{(1-x)^2} \]

即有:

\[\begin{aligned} ans&=[x^m]G(x)F^n(x)\\ &=[x^m]\frac{x}{(1-x)^2}\frac{x^n((1+2k)+(1-2k)x)^n}{(1-x)^{3n}}\\ &=[x^m]\frac{x^{n+1}((1+2k)+(1-2k)x)^n}{(1-x)^{3n+2}}\\ &=[x^{m-n-1}]\frac{((1+2k)+(1-2k)x)^n}{(1-x)^{3n+2}}\\ \end{aligned} \]

注意到:

\[\frac{1}{(1-x)^k}=\sum_{i\geq 0}{i+k-1\choose i}x^i \]

因此有:

\[\begin{aligned} ans&=[x^{m-n-1}]\frac{((1+2k)+(1-2k)x)^n}{(1-x)^{3n+2}}\\ &=[x^{m-n-1}]\left(\sum_{i\geq 0}{i+3n+1\choose i}x^i\right)\left(\sum_{j=0}^{n}{n\choose j}(1+2k)^{n-j}(1-2k)^{j}x^{j}\right)\\ \end{aligned} \]

预处理后就可以 \(O(n)\) 求了。

const int N=4e6+5;
int n,m,k,l,f1[N],f2[N],fac[N],inv[N];

inline void init_f(int L=N-5) {
    fac[0]=1;
    lep(i,1,L) fac[i]=mul(fac[i-1],i);
    inv[L]=modpow(fac[L],mod-2);
    rep(i,L,1) inv[i-1]=mul(inv[i],i);
}

inline int C(int n,int m) {
    if(n<m||n<0||m<0) return 0;
    return mul(fac[n],mul(inv[m],inv[n-m]));
}

int main() {
    init_f();
    IN(n,m,k),l=m-n-1,k<<=1;

    f1[0]=f2[0]=1;
    lep(i,1,n) f1[i]=mul(f1[i-1],add(1,k)),f2[i]=mul(f2[i-1],dec(1,k));

    int ans=0;
    lep(i,0,l) {
        int r1=C(i+3*n+1,i);
        int r2=mul(C(n,l-i),mul(n-l+i<0?0:f1[n-l+i],f2[l-i]));
        pls(ans,mul(r1,r2));
    }
    printf("%d\n",ans);
    return 0;
}
posted @ 2020-10-17 09:48  Moonlightsqwq  阅读(108)  评论(0编辑  收藏  举报