younik要挂号(排列组合+思维)

younik要挂号

分析:
先从每个数中选n-1个不同的数(共C(n-1,m)种选法),
选出来的n-1个数中最大的那个数一定是序列的峰值,
再从那n-2个数中选出那个要重复一次的数(共C(n-2,1)种选法),
余下的n-3个数中的每个数要么在峰值左侧要么在右侧(共2^(n-3)种选法) 。
因此有:C(n-1,m)*C(1,n-2)*2^(n-3)。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
const ll mod=998244353; 
int n,m;
ll f[N],sum=0;
ll qpow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b=b>>1;
	}
	return res;
}
void Init(){
	f[0]=1;
	for(int i=1;i<N;i++) f[i]=f[i-1]*(ll)i%mod;
}
int main(){
	/*
	先从每个数中选n-1个不同的数(共C(n-1,m)种选法),
	选出来的n-1个数中最大的那个数一定是序列的峰值,
	再从那n-2个数中选出那个要重复一次的数(共C(n-2,1)种选法)
	余下的n-3个数中的每个数要么在峰值左侧要么在右侧(共2^(n-3)种选法) 
	因此有:C(n-1,m)*C(1,n-2)*2^(n-3)
	*/
	
	Init();
   scanf("%d %d",&n,&m);
    if(n==2) printf("0\n");
    else{
        ll sum=(n-2)*qpow(2,n-3)%mod*f[m]%mod*qpow(f[m-n+1]*f[n-1]%mod,mod-2)%mod;//C(n-1,m)*C(1,n-2)*2^(n-3)
   	
	printf("%lld\n",sum);
    }
   
	
	
	
	return 0;
}
 
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值