洛谷P5548 [BJ United Round #3] 押韵

题解

$$d = 6$$

$$F(x, y) = x + x^2 + x^2y + y + y^2 + y^2x$$

$$x$$ 求导，有 $$\displaystyle \frac {\partial G} {\partial x} = k F^{k - 1} \frac {\partial F} {\partial x}$$，令两边系数对应相等，有：

\begin{aligned} &\ ng_{n, m} + (n - 1) g_{n - 1, m} + (n - 1) g_{n - 1, m - 1} + (n + 1) g_{n + 1, m - 1} + (n + 1)g_{n + 1, m - 2} + n g_{n, m - 2}\\ =&\ k(g_{n, m} + 2g_{n - 1, m} + 2g_{n - 1, m - 1} + g_{n, m - 2}) \end{aligned}

$$g_{n + 1, m - 1}$$ 移到一边然后令 $$n \gets n - 1, m \gets m + 1$$ 可得：

$n g_{n, m} = (k - n + 1) (g_{n - 1, m + 1} + g_{n - 1, m - 1}) + (2k - n + 2) (g_{n - 2, m + 1} + g_{n - 2, m}) - n g_{n, m - 1}$

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

{
int data = 0, w = 1; char ch = getchar();
while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
return data * w;
}

const int N(2010), Mod(1049874433);
inline int upd(const int &x) { return x + (x >> 31 & Mod); }
int fastpow(int x, int y)
{
int ans = 1;
for (; y; y >>= 1, x = 1ll * x * x % Mod)
if (y & 1) ans = 1ll * ans * x % Mod;
return ans;
}

int n, K, D, w, pw[10], fac[N], inv[N], dK;
int C(int n, int m) { return 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod; }

{
int a[10], ans, res;
void calc()
{
for (int i = res = 0; i < D; i++) res = (res + 1ll * a[i] * pw[i]) % Mod;
res = fastpow(res, n);
for (int i = 0; i < D; i++) res = 1ll * res * inv[a[i]] % Mod;
ans = (ans + 1ll * res * fac[K]) % Mod;
}

void dfs(int x, int k)
{
if (x == D - 1) return a[x] = k, calc();
for (int i = 0; i <= k; i++) a[x] = i, dfs(x + 1, k - i), a[x] = 0;
}

void main()
{
dfs(0, K);
printf("%lld\n", 1ll * ans * dK % Mod);
}
}

{
void main()
{
int ans = 0;
for (int i = 1; i <= K; i++)
for (int j = 0; i + j <= K; j++)
{
if ((i + j + K) & 1) continue;
int cnt = 1ll * C(K, (K + i + j) >> 1) * C(K, (K + std::abs(i - j)) >> 1) % Mod;
ans = (ans + 1ll * fastpow((i + 1ll * j * w) % Mod, n) * cnt) % Mod;
}
printf("%lld\n", 4ll * ans * dK % Mod);
}
}

{
int g[N << 1][N << 1], m, ans, rev[N << 1];

void main()
{
m = K << 1, rev[1] = 1;
for (int i = 2; i <= m; i++) rev[i] = 1ll * (Mod - Mod / i) * rev[Mod % i] % Mod;
for (int i = 0; i <= K; i++) g[i][K - i] = C(K, i);
for (int i = K + 1; i <= m; i++) g[i][0] = g[0][i] = C(K, i - K);
for (int i = 1; i <= m; i++)
for (int j = std::max(K - i + 1, 1); j <= m; j++)
{
g[i][j] = 1ll * (K - i + 1) * (g[i - 1][j + 1] + g[i - 1][j - 1]) % Mod;
if (i > 1) g[i][j] = (g[i][j] + 1ll * (((K + 1) << 1) - i) * (g[i - 2][j + 1] + g[i - 2][j])) % Mod;
g[i][j] = (g[i][j] - 1ll * i * g[i][j - 1]) % Mod;
g[i][j] = 1ll * g[i][j] * rev[i] % Mod;
}
for (int i = 0; i <= m; i++) for (int j = 0; j <= m; j++) if (g[i][j])
ans = (ans + 1ll * g[i][j] * fastpow((i - K + 1ll * (j - K) * w) % Mod, n)) % Mod;
printf("%lld\n", 1ll * upd(ans) * dK % Mod);
}
}

int main()
{
#ifndef ONLINE_JUDGE
file(cpp);
#endif
n = read(), K = read(), D = read(), n = 1ll * n * D % (Mod - 1);
w = fastpow(7, (Mod - 1) / D), fac[0] = pw[0] = 1;
for (int i = 1; i < D; i++) pw[i] = 1ll * pw[i - 1] * w % Mod;
for (int i = 1; i <= K; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
inv[K] = fastpow(fac[K], Mod - 2), dK = fastpow(fastpow(D, K), Mod - 2);
for (int i = K; i; i--) inv[i - 1] = 1ll * inv[i] * i % Mod;
return 0;
}

posted @ 2021-03-12 11:27  xgzc  阅读(175)  评论(0编辑  收藏  举报