感谢强大 alpha!!1【1】
我们要求的是:
考虑凑
因此:
考虑到
于是:
后面的最高项是
别以为初值就是子问题!注意
const int N = 1e7 + 5;
int n, m, L[6], R[5], H[6], G[N];
signed main () {
IN (n), IN (m);
// get L
L[1] = 1;
L[2] = 1;
L[3] = mod - 1;
L[4] = mod - 1;
// get R
R[0] = 1;
R[1] = n - m;
R[2] = n - m + 1;
rep (i, 2, 0) {
pls (R[i + 2], mul (mod - 1, R[i]));
pls (R[i + 1], mul (2, R[i]));
}
// get fac[n - m]
int pot = (n - m) / B, buf = rec[pot];
lep (i, pot * B + 1, n - m) buf = mul (buf, i);
int fix = qpow (mod - R[0], mod - 2);
int ori = mul (((m & 1) ? mod - 1 : 1), buf);
lep (i, 0, m) {
lep (j, 1, min (4, i)) {
pls (G[i], mul (L[j], mul (i - j, G[i - j])));
pls (G[i], mul (R[j], G[i - j]));
}
if (i <= 3) sub (G[i], mul ((i == 2 ? mod - 3 : 1), ori));
G[i] = mul (fix, G[i]);
}
printf ("%d\n", G[m]);
return 0;
}