2021牛客寒假算法基础集训营5 B 比武招亲(上)

链接 https://ac.nowcoder.com/acm/contest/9985/B

思路
打表,得出一个7X7的表,根据行(m相同的情况下)找规律
第一行差分数列可以写成组合数形式C(n, 3),接下来自然而然推出来了
1C(n, 3)
2
C(n, 4)
3*C(n, 5)
记得预处理1e6的阶乘,不是5e5,wa了一发,挺可惜的

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 5e6+5;
const double esp = 1e-6;
const ll mod = 998244353; 
int n,m;
ll f[N];
ll qpow(ll a,ll b){
	ll ans=1,base=a;
	while(b){
		if(b&1) ans=ans*base%mod;
		base=base*base%mod;
		b>>=1;
	}
	return ans;
}
void init(){
	f[1]=1;
	f[0]=1;
    for(int i=2;i<N;i++) {
    	f[i]=f[i-1]*i%mod;
	}	
}
ll cal(ll n,ll m){
	if(m>n||m<0||n<0) return 0;
	return 1ll*f[n]*qpow(f[m],mod-2)%mod*qpow(f[n-m],mod-2)%mod;
}
void solve(){
	scanf("%d %d",&n,&m);
	printf("%lld",(m-1)*cal(n+m-1,m+1)%mod);
}
int main(){
	int Case=1;
	init();
	//scanf("%d",&Case);
	while(Case--){
		solve();
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值