# 【组合数学】AGC036C - GP 2

## Problem Statement

We have a sequence of $N$ integers: $x=(x_0,x_1,\cdots,x_{N−1})$. Initially, $x_i=0$ for each $i (0≤i≤N−1)$.

Snuke will perform the following operation exactly $M$ times:

Choose two distinct indices $i,j (0≤i,j≤N−1, i≠j)$. Then, replace $x_i$ with $x_i+2$ and $x_j$ with $x_j+1$.
Find the number of different sequences that can result after $M$ operations. Since it can be enormous, compute the count modulo $998244353$.

## Constraints

• $2≤N≤10^6$
• $1≤M≤5×10^5$
• All values in input are integers.

## 题目分析

 1 #include<bits/stdc++.h>
2 #define MO 998244353
3 typedef long long ll;
4 const int maxn = 3000000;
5
6 ll n,m,ans;
7 ll inv[maxn],fac[maxn];
8
9 ll C(ll n, ll m)
10 {
11     if (n < m) return 0;
12     return fac[n]*inv[m]%MO*inv[n-m]%MO;
13 }
14 ll f(ll n, ll m, ll k)
15 {
16     ll ret = 0;
17     for (ll p=0; p<=k; p++)
18         if (((m-p)&1)==0){
19             ret = (ret+C((m-p)/2ll+n-1, n-1)*C(n, p)%MO)%MO;
20         }
21     return ret;
22 }
23 int main()
24 {27     scanf("%lld%lld",&n,&m);
28     fac[0] = inv[0] = inv[1] = 1;
29     for (int i=2; i<=n+3*m; i++)
30         inv[i] = (MO-1ll*MO/i*inv[MO%i]%MO);
31     for (int i=1; i<=n+3*m; i++)
32         inv[i] = inv[i-1]*inv[i]%MO, fac[i] = fac[i-1]*i%MO;
33 //    ans = (f(n, 3*m, m)-n*(f(n, m, m)-f(n-1, m, m))%MO+MO)%MO;
34     ans = (f(n, 3*m, m)-n*(f(n, m-1, m))%MO+MO)%MO;
35     printf("%lld\n",ans);
36     return 0;
37 }

END

posted @ 2019-11-03 18:18  AntiQuality  阅读(187)  评论(0编辑  收藏  举报