题解【LOJ3300】「联合省选 2020 A」组合数问题

题面

先了解一个柿子:\(\binom{n}{k} \times k^{\underline m} = \binom{n-m}{k-m} \times n^{\underline m}\)

证明:

\[\begin{aligned} \binom{n}{k} \times k^{\underline m} &= \frac{n!}{k!(n-k)!}\times \frac{k!}{(k-m)!} \\ &= \frac{n!}{(n-k)!(k-m)!} \\ &= \frac{n!(n-m)!}{(n-k)!(k-m)!(n-m)!} \\ &= \binom{n-m}{k-m}\frac{n!}{(n-m)!} \\ &= \binom{n-m}{k-m}n^{\underline m} \end{aligned}\]

我们发现题目中的多项式不是很好算,于是把它改成下降幂形式:

\[f(k)=\sum\limits_{i=1}^m a_ik^i=\sum\limits_{i=1}^m b_ik^{\underline i} \]

考虑怎么求 \(b_i\)

\[\begin{aligned} \sum\limits_{i=0}^m a_ik^i &= \sum\limits_{i=0}^m a_i\sum\limits_{j=0}^i \binom{k}{j}{i\brace j}j! \\ &= \sum\limits_{i=0}^m a_i\sum\limits_{j=0}^i k^{\underline j}{i\brace j}\\ &= \sum\limits_{j=0}^m k^{\underline j}\sum\limits_{i=j}^m {i\brace j}a_i \end{aligned}\]

所以 \(b_i=\sum\limits_{j=i}^m {j\brace i}a_j\)

然后就开始推式子:

\[\begin{aligned} \sum\limits_{k=0}^n\sum\limits_{i=0}^m b_ik^{\underline{i}}x^k\binom{n}{k} &= \sum\limits_{k=0}^n\sum\limits_{i=0}^m \binom{n-i}{k-i}n^{\underline{i}}b_ix^k \\ &= \sum\limits_{i=0}^m b_in^{\underline{i}}\sum\limits_{k=0}^n \binom{n-i}{k-i}x^k\\ &= \sum\limits_{i=0}^m b_in^{\underline{i}}\sum\limits_{k=0}^{n-i}x^{k+i}\binom{n-i}{i} \\ &= \sum\limits_{i=0}^m b_in^{\underline{i}} x^i\sum\limits_{k=0}^{n-i}\binom{n-i}{i}x^k1^{n-i-k} \\ &= \sum\limits_{i=0}^m b_in^{\underline{i}}x^i(x+1)^{n-i} \end{aligned}\]

可以 \(\mathcal{O}(m^2)\) 求解。

代码:

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

template <typename T>
inline T gi()
{
	T f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 1003, M = N << 1;

int n, x, p, m;
LL a[N], b[N], s[N][N], ans;

inline LL qpow(LL g, LL u)
{
	LL res = 1;
	while (u)
	{
		if (u & 1) res = res * g % p;
		g = g * g % p, u >>= 1;
	}
	return res;
}

int main()
{
	//File("");
	n = gi <int> (), x = gi <int> (), p = gi <int> (), m = gi <int> ();
	s[0][0] = 1;
	for (int i = 1; i <= m; i+=1)
		for (int j = 1; j <= i; j+=1)
			s[i][j] = (s[i - 1][j - 1] + 1ll * j * s[i - 1][j] % p) % p;
	for (int i = 0; i <= m; i+=1) a[i] = gi <int> ();
	for (int i = 0; i <= m; i+=1)
		for (int j = i; j <= m; j+=1)
			b[i] = (b[i] + s[j][i] * a[j] % p) % p;
	for (int i = 0; i <= m; i+=1)
	{
		LL tmp = 1;
		for (int j = n - i + 1; j <= n; j+=1) tmp = tmp * j % p;
		LL now = b[i] % p * tmp % p * qpow(x, i) % p * qpow(x + 1, n - i) % p;
		ans = (ans + now) % p;
	}
	printf("%lld\n", ans);
	return 0;
}
posted @ 2020-08-27 21:39  csxsi  阅读(149)  评论(0编辑  收藏  举报