codeforces1312D 组合数学

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值