题解:P14461 【MX-S10-T2】『FeOI-4』青年晚报

· · 题解

前情提要:

本做法为笔者赛时找规律做法,没有对结论加以证明,如需证明请看其他大佬题解,谢谢。

考虑:

F_i(x) = F_{i - 2}(x) - {F_{i - 2}} ^ {(2)}(x)

继续拆:

F_i(x) = F_{i - 4}(x) - 2{F_{i - 4}} ^ {(2)}(x) + {F_{i - 4}} ^ {(4)}

继续:

F_i(x) = F_{i - 6}(x) - 3{F_{i - 6}} ^ {(2)}(x) + 3{F_{i - 6}} ^ {(4)}(x) - {F_{i - 6}} ^ {(6)}(x)

依次类推,我们观察一下系数:

1,-1 \\ 1,-2,1 \\ 1,-3,3,-1 \end{align*}

发现拆开 i 次系数是 (-1) ^ j 乘上杨辉三角的第 i 层的每个数,然后由于 F_0(x) 是一个 m 次多项式,所以对 F_0(x) 求大于 m 阶导的时候每一项都是 0,没有贡献了,所以只需要展开 \min(\lfloor \frac{n}{2}\rfloor,\lceil \frac{m}{2} \rceil) 项。

然后如果 n 是偶数,直接算 F_0(x) 的若干阶导即可,否则算出 F_1(x) 然后算 F_1(x) 的若干阶导。

然后由于 n 很大,m 很小,暴力算组合数即可。

时间复杂度 \mathcal O(m ^ 2)。 :::success[代码]

#include <bits/stdc++.h>

#define int long long

constexpr int N = 5005,mod = 1e9 + 7;

int n,m,fac[N],inv[N];

struct Poly{
    std::vector<int> F;
    Poly(){
        F.resize(m + 1,0);
    }
};

Poly operator + (const Poly & a,const Poly & b){
    Poly c;
    for(int j = 0; j <= m; ++ j){
        c.F[j] = (a.F[j] + b.F[j]) % mod;
    }
    return c;
}
Poly operator - (const Poly & a,const Poly & b){
    Poly c;
    for(int j = 0; j <= m; ++ j){
        c.F[j] = (a.F[j] - b.F[j] + mod) % mod;
    }
    return c;
}
Poly der(Poly a){
    Poly c;
    for(int j = 0; j < m; ++ j){
        c.F[j] = 1ll * (j + 1) * a.F[j + 1] % mod;
    }
    return c;
}
Poly Mul(Poly a,int k){
    Poly c;
    for(int j = 0; j <= m; ++ j){
        c.F[j] = k * a.F[j] % mod;
    }
    return c;
}
inline int ksm(int x,int y){
    int ans = 1;
    while(y){
        if(y & 1) ans = ans * x % mod;
        x = x * x % mod; y >>= 1;
    }
    return ans;
}
inline int C(int x,int y){
    int ans = 1;
    for(int i = x - y + 1; i <= x; ++ i) ans = ans * i % mod;
    return ans * inv[y] % mod;
}
signed main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cin >> n >> m;
    Poly F,G,ans_F,ans_G,F_,G_;
    for(int i = 0; i <= m; ++ i){
        std::cin >> F.F[i];
    }
    for(int i = 0; i <= m; ++ i){
        std::cin >> G.F[i];
    }
    F_ = F; G_ = G;
    fac[0] = inv[0] = 1;
    for(int i = 1; i <= m; ++ i){
        fac[i] = fac[i - 1] * i % mod;
    }
    inv[m] = ksm(fac[m],mod - 2);
    for(int i = m - 1; i >= 1; -- i){
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
    if(n & 1){
        Poly last = F;
        F = G + der(G);
        G = last - der(last);
        F_ = F; G_ = G; -- n;
    }
//  if(n % 2 == 0){
//      F_ = der(F_);
//      F_ = der(F_);
//      for(int i = 0; i <= m; ++ i){
//          std::cout << F_.F[i] << ' ';
//      }
//      std::cout << '\n';
    for(int i = 0; i <= n / 2; ++ i){
        if(i * 2 > m) break;
        if(i & 1){
            ans_F = ans_F - Mul(F_,C(n / 2,i));
            ans_G = ans_G - Mul(G_,C(n / 2,i));
        }else{
            ans_F = ans_F + Mul(F_,C(n / 2,i)); 
            ans_G = ans_G + Mul(G_,C(n / 2,i));
        }
//          for(int j = 0; j <= m; ++ j){
//              std::cout << ans.F[j] << ' ';
//          }
//          std::cout << '\n';
        F_ = der(F_);
        F_ = der(F_);
        G_ = der(G_);
        G_ = der(G_);
    }
//  }
    for(int i = 0; i <= m; ++ i){
        std::cout << ans_F.F[i] << ' ';
    }
    std::cout << '\n';
    for(int i = 0; i <= m; ++ i){
        std::cout << ans_G.F[i] << ' ';
    }
    return 0;
}

:::