bzoj 4126 国王奇遇记加强版之再加强版 (伪
这里给出一种基于有限微积分的做法,由于求斯特林数时需要不定模数FNT,于是不太跑的过 ……
先转下降幂
$$\begin{align*}\sum_{t=0}^{n}{t^qq^t}&=\sum_{t=0}^{n}
\sum_{p=0}^{q}{q\brace p}t^{\underline{p}}q^t\\&=\sum_
{p=0}^{q}{q\brace p}\sum_{0}^{n+1}{t^\underline{p}q^t}
\delta t\end{align*}$$
令 $u=t^\underline{p},\Delta v=q^t$
于是有
$\Delta u=pt^\underline{p-1},v=\frac{q^t}{q-1},Ev=
\frac{q^{t+1}}{q-1}$
根据 $\sum{u\Delta v}=uv-\sum{Ev\Delta u}$
因此
$$\begin{align*}\sum_{0}^{n+1}{t^\underline{p}q^t} \delta t&=(n+1)^\underline{p}\times\frac{q^{n+1}}{q-1}-\sum_ {0}^{n+1}{\frac{q^{t+1}}{q-1}\times pt^\underline {p-1}}\delta t\\&=\frac{1}{q-1}((n+1)^\underline{p}q^{n+1}- pq\sum_{0}^{n+1}{t^\underline{p-1}q^t\delta t}) \end{align*}$$
由于
$$\begin{align*}\sum_{0}^{n+1}t^{\underline{0}}q^t
\delta t&=\frac{q^t}{q-1}\Big|^{n+1}_0\\&=\frac{q^
{n+1}-1}{q-1}\end{align*}$$
于是形如 $\sum_{t=0}^{n}{t^\underline{p}q^t}$ 的式子就可以
$O(p)$ 计算了。
bzoj 3157 国王奇遇记的代码:
#include <bits/stdc++.h> using namespace std; const int N = 2000; const int MOD = 1e9 + 7; int n, m; int S[N][N]; int val[N], sum[N], res; int powi(int a, int b) { if (b < 0) b += MOD - 1; int c = 1; for (; b; b >>= 1, a = 1ll * a * a % MOD) if (b & 1) c = 1ll * c * a % MOD; return c; } int main() { scanf("%d%d", &n, &m); for (int i = 0; i <= m; ++ i) { S[i][0] = 0; S[i][i] = 1; for (int j = 1; j < i; ++ j) S[i][j] = (S[i - 1][j - 1] + 1ll * j * S[i - 1][j]) % MOD; } if (m == 1) return printf("%d\n", 1ll * n * (n + 1) / 2 % MOD), 0; val[0] = 1ll * powi(m, n + 1) * powi(m - 1, -1) % MOD; sum[0] = 1ll * (powi(m, n + 1) - 1 + MOD) * powi(m - 1, -1) % MOD; for (int i = 1; i <= m; ++ i) { val[i] = 1ll * val[i - 1] * (n - i + 2) % MOD; sum[i] = (val[i] - 1ll * m * i % MOD * powi(m - 1, -1) % MOD * sum[i - 1] % MOD + MOD) % MOD; } for (int i = 0; i <= m; ++ i) res = (res + 1ll * S[m][i] * sum[i]) % MOD; printf("%d\n", res); }