1312D 1700
题意:给你n个位置和m个数,在m个数中挑出n-1个数放入到n个位置中,其中有一个数可以用两次,同时要使得这n个数的排列为先上升后下降,问有多少种排列方式
思路:首先从m个数中挑出n-1个数为C(m,n-1),
然后选择其中重复两次的数,最大值不能选,所以乘上n-2,
之后对n个数的位置进行讨论,我们可以知道,重复两次的的数一定在最大值两边,然后其他n-3(一个为最大值,两个为相同的)个数可能在最大值左边也可能在最大值右边,所以有2^(n-3),
综上所述,答案就出来了,主要就是算法问题,吐血
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define rep(i, a, n) for(int i = a; i <= n; i++)
#define per(i, a, n) for(int i = n; i >= a; i--)
#define IOS std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define fopen freopen("file.in","r",stdin);freopen("file.out","w",stdout);
#define fclose fclose(stdin);fclose(stdout);
const int inf = 1e9;
const ll onf = 1e18;
const int maxn = 1e5+10;
const int mod = 998244353;
inline int read(){
int x=0,f=1;char ch=getchar();
while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-48;ch=getchar();}
return x*f;
}
ll qpow(ll a, ll b){
ll res = 1;
while(b>0){
if(b&1) res = (res*a)%mod;
a = (a*a)%mod;
b >>= 1;
}
return res;
}
ll comb(ll n, ll m){ // C(n,m)
ll tmp = 1, res = 1;
for(int i = 1; i <= n; i++) res = res*i%mod;
for(int i = 1; i <= m; i++) tmp = tmp*i%mod;
for(int i = 1; i <= n-m; i++) tmp = tmp*i%mod;
return res*qpow(tmp, mod-2)%mod;
}
signed main(){
int n=read(), m=read();
printf("%lld\n", (comb(m,n-1)*(n-2)%mod)*qpow(2,n-3)%mod);
return 0;
}