当前位置:网站首页>AtCoder Beginner Contest 248C Dice Sum (生成函数)
AtCoder Beginner Contest 248C Dice Sum (生成函数)
2022-04-23 13:51:00 【MoYan1082】
AtCoder Beginner Contest 248C Dice Sum
题意
给定三个整数 N , M , K N,M,K N,M,K,求有多少种满足以下条件的序列 A A A:
- A A A长度为 N N N;
- 1 ≤ A i ≤ M ( 1 ≤ i ≤ N ) 1\le A_i\le M(1\le i\le N) 1≤Ai≤M(1≤i≤N)
- ∑ i = 1 N A i ≤ K \sum_{i=1}^N A_i\le K ∑i=1NAi≤K
最后的结果对998244353
取模。
思路
对于每一个 A i A_i Ai,可以用 f ( x ) = 0 + x + x 2 + . . . + x M = x 1 − x M 1 − x f(x)=0+x+x^2+...+x^M=x\frac{1-x^M}{1-x} f(x)=0+x+x2+...+xM=x1−x1−xM来表示。
令 F ( x ) = f ( x ) N F(x)=f(x)^N F(x)=f(x)N,那么结果就是 ∑ i = 0 k [ x i ] F ( x ) \sum_{i=0}^k [x^i]F(x) ∑i=0k[xi]F(x)。
令 G ( x ) = F ( x ) ∗ ( 1 + x + x 2 + . . . ) = F ( x ) ∗ 1 1 − x G(x)=F(x)*(1+x+x^2+...)=F(x)*\frac{1}{1-x} G(x)=F(x)∗(1+x+x2+...)=F(x)∗1−x1,则
[ x k ] G ( x ) = ∑ i = 0 k [ x k ] F ( x ) ∗ [ x k − i ] 1 1 − x = ∑ i = 0 k [ x k ] F ( x ) \begin{matrix} [x^k]G(x)&=&\sum_{i=0}^{k}[x^k]F(x)*[x^{k-i}]\frac{1}{1-x} \\ \\ &=&\sum_{i=0}^k[x^k]F(x) \end{matrix} [xk]G(x)==∑i=0k[xk]F(x)∗[xk−i]1−x1∑i=0k[xk]F(x)
又因:
G ( x ) = F ( x ) ∗ 1 1 − x = x N ( 1 − x M ) N ( 1 − x ) − ( N + 1 ) G(x)=F(x)*\frac{1}{1-x}=x^N(1-x^M)^N(1-x)^{-(N+1)} G(x)=F(x)∗1−x1=xN(1−xM)N(1−x)−(N+1)
故: [ x k ] G ( x ) = [ x k − N ] ( 1 − x M ) N ( 1 − x ) − ( N + 1 ) [x^k]G(x)=[x^{k-N}](1-x^M)^N(1-x)^{-(N+1)} [xk]G(x)=[xk−N](1−xM)N(1−x)−(N+1)。
其中
( 1 − x M ) N = ∑ i = 0 N ( N i ) ( − x M ) i = ∑ i = 0 N ( − 1 ) i N ! i ! ( N − i ) ! x i × M (1-x^M)^N=\sum_{i=0}^N\binom{N}{i}(-x^M)^i=\sum_{i=0}^N(-1)^i\frac{N!}{i!(N-i)!}x^{i\times M} (1−xM)N=i=0∑N(iN)(−xM)i=i=0∑N(−1)ii!(N−i)!N!xi×M
令 h ( x ) = ( 1 − x ) − ( N + 1 ) h(x)=(1-x)^{-(N+1)} h(x)=(1−x)−(N+1),则:
h ( x ) = ( 1 − x ) − N − 1 h ′ ( x ) = ( − N − 1 ) ( − 1 ) ( 1 − x ) − N − 2 = ( N + 1 ) ( 1 − x ) − N − 2 h ′ ′ ( x ) = ( − N − 1 ) ( − N − 2 ) ( − 1 ) 2 ( 1 − x ) − N − 3 = ( N + 1 ) ( N + 2 ) ( 1 − x ) − N − 3 ⋯ h ( i ) ( x ) = ( N + 1 ) ( N + 2 ) ⋯ ( N + i ) ( 1 − x ) − N − 3 = ( N + i ) ! N ! ( 1 − x ) − N − 3 \begin{matrix} h(x)&=&(1-x)^{-N-1}\\ \\ h'(x)&=&(-N-1)(-1)(1-x)^{-N-2}&=&(N+1)(1-x)^{-N-2} \\ \\ h''(x)&=&(-N-1)(-N-2)(-1)^2(1-x)^{-N-3}&=&(N+1)(N+2)(1-x)^{-N-3} \\ \\ \cdots \\ \\ h^{(i)}(x)&=&(N+1)(N+2)\cdots (N+i)(1-x)^{-N-3} &=& \frac{(N+i)!}{N!} (1-x)^{-N-3} \\ \\ \end{matrix} h(x)h′(x)h′′(x)⋯h(i)(x)====(1−x)−N−1(−N−1)(−1)(1−x)−N−2(−N−1)(−N−2)(−1)2(1−x)−N−3(N+1)(N+2)⋯(N+i)(1−x)−N−3===(N+1)(1−x)−N−2(N+1)(N+2)(1−x)−N−3N!(N+i)!(1−x)−N−3
由泰勒公式,得:
h ( x ) = h ( 0 ) + h ′ ( 0 ) x 1 ! + h ′ ′ ( 0 ) x 2 2 ! + . . . + h ( n ) ( 0 ) x n n ! + . . . h(x)=h(0)+\frac{h'(0)x}{1!}+\frac{h''(0)x^2}{2!}+...+\frac{h^{(n)}(0)x^n}{n!}+... h(x)=h(0)+1!h′(0)x+2!h′′(0)x2+...+n!h(n)(0)xn+...
[ x i ] h ( x ) = h ( i ) ( 0 ) i ! x i = ( N + i ) ! N ! i ! x i [x^i]h(x)=\frac{h^{(i)}(0)}{i!}x^i=\frac{(N+i)!}{N!i!}x^i [xi]h(x)=i!h(i)(0)xi=N!i!(N+i)!xi
结果为:
[ x k − N ] ( 1 − x M ) N ( 1 − x ) − ( N + 1 ) = ∑ i ≥ 0 ( − 1 ) i N ! i ! ( N − i ) ! × ( N + ( K − N − i × M ) ) ! N ! ( K − N − i × M ) ! = ∑ i ≥ 0 ( − 1 ) i N ! i ! ( N − i ) ! × ( N + ( K − N − i × M ) ) ! N ! ( K − N − i × M ) ! = ∑ i ≥ 0 ( − 1 ) i ( K − i × M ) ! ( K − N − i × M ) ! × i ! ( N − i ) ! \begin{matrix} [x^{k-N}](1-x^M)^N(1-x)^{-(N+1)} &=&\sum_{i\ge0}(-1)^i\frac{N!}{i!(N-i)!}\times \frac{(N+(K-N-i\times M))!}{N!(K-N-i\times M)!} \\ \\ &=&\sum_{i\ge0}(-1)^i\frac{N!}{i!(N-i)!}\times \frac{(N+(K-N-i\times M))!}{N!(K-N-i\times M)!} \\ \\ &=&\sum_{i\ge0}(-1)^i\frac{(K-i\times M)!}{(K-N-i\times M)!\times i!(N-i)!} \\ \\ \end{matrix} [xk−N](1−xM)N(1−x)−(N+1)===∑i≥0(−1)ii!(N−i)!N!×N!(K−N−i×M)!(N+(K−N−i×M))!∑i≥0(−1)ii!(N−i)!N!×N!(K−N−i×M)!(N+(K−N−i×M))!∑i≥0(−1)i(K−N−i×M)!×i!(N−i)!(K−i×M)!
其中 i × M ≤ K − N i\times M\le K-N i×M≤K−N。
AC的代码
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 998244353;
const int N = 1e6 + 10;
ll fac[N], n, m, k;
ll power(ll a, ll b) {
ll res = 1;
while (b) {
if (b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
ll inv(ll x) {
return power(x, mod - 2); }
void init() {
fac[0] = 1;
for (int i = 1; i <= N - 10; i++) fac[i] = fac[i - 1] * i % mod;
}
int main() {
init();
cin >> n >> m >> k;
ll res = 0;
for (int i = 0;; i++) {
if (i * m > k - n) break;
ll tmp = fac[k - i * m] * inv(fac[i]) % mod * inv(fac[n - i]) % mod *
inv(fac[k - n - i * m]) % mod;
res = ((res + (i % 2 ? -1 : 1) * tmp) % mod + mod) % mod;
}
cout << res;
return 0;
}
版权声明
本文为[MoYan1082]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_45874328/article/details/124358826
边栏推荐
- Detailed explanation of redis (Basic + data type + transaction + persistence + publish and subscribe + master-slave replication + sentinel + cache penetration, breakdown and avalanche)
- Oracle clear SQL cache
- Oracle generates millisecond timestamps
- Processing of ASM network not automatically started in 19C
- Lenovo Saver y9000x 2020
- Express②(路由)
- UML Unified Modeling Language
- Apache Atlas Compilation and installation records
- TCP reset Gongji principle and actual combat reproduction
- L2-024 部落 (25 分)
猜你喜欢
JUC interview questions about synchronized, ThreadLocal, thread pool and atomic atomic classes
Dolphin scheduler integrates Flink task pit records
神经元与神经网络
Solution of discarding evaluate function in surprise Library
Set Jianyun x Feishu Shennuo to help the enterprise operation Department realize office automation
Kettle--控件解析
UML统一建模语言
Tersus notes employee information 516 MySQL query (time period uniqueness judgment of 2 fields)
Android interview theme collection
10g database cannot be started when using large memory host
随机推荐
Window function row commonly used for fusion and de duplication_ number
Small case of web login (including verification code login)
Publish custom plug-ins to local server
ARGB transparency conversion
服务器中挖矿病毒了,屮
Information: 2021 / 9 / 29 10:01 - build completed with 1 error and 0 warnings in 11S 30ms error exception handling
Resolution: argument 'radius' is required to be an integer
Utilisation de GDB
Oracle generates millisecond timestamps
Dynamic subset division problem
Oracle modify default temporary tablespace
聯想拯救者Y9000X 2020
Zero copy technology
[Video] Bayesian inference in linear regression and R language prediction of workers' wage data | data sharing
19c RAC steps for modifying VIP and scanip - same network segment
leetcode--380.O(1) 时间插入、删除和获取随机元素
Solution of discarding evaluate function in surprise Library
pycharm Install packages failed
SQL learning window function
Reading notes: meta matrix factorization for federated rating predictions