CF1312 D. Count the Arrays

给要求$[1,x]$单调增,$[x,n]$单调减。可以有$m$种值,需要有两个相同元素,求有多少种这样的数列

有两个一定是独一无二的最大值,和相同的元素。

剩余只要考虑是放在右边还是左边=$2^{n-3}$
选的方案$C(m,n-1)*(n-2),ans=C(m,n-1)\times(n-2)\times2^{n-3}$

代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const int mod = 998244353;
ll qpow(ll a, ll x, ll mo)
{
ll res = 1;
while (x)
{
if (x & 1)
res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
x >>= 1;
}
return res;
}
int fac[N], facinv[N];
void prepare()
{
fac[0] = 1;
facinv[0] = 1;
for (int i = 1; i < N; i++)
fac[i] = 1ll * fac[i - 1] * i % mod;
facinv[N - 1] = qpow(fac[N - 1], mod - 2, mod);
for (int i = N - 2; i >= 1; i--)
facinv[i] = 1ll * facinv[i + 1] * (i + 1) % mod;
}
ll calc(ll i, ll n)
{
if (n <= 0)
return 0;
if (i > n)
return 0;
if (i == 0)
return 1;
return 1ll * fac[n] * facinv[i] % mod * facinv[n - i] % mod;
}
int n, m, res;

int main()
{
prepare();
cin >> n >> m;
if (n < 3)
cout << 0 << endl;
//cout << 233 << endl;
else
cout << 1ll * calc(n - 1, m) * (n - 2) % mod * qpow(2, n - 3, mod) % mod << endl;
}