洛谷P2767 树的数量

题目

Solution

1.题解
2.我们班长给出的证明(举例中的I=6):


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=23333;
int x,y;
ll n,m;
void ex_gcd(int a,int b,int &x,int &y){
	if (!b) x=1,y=0;
	else ex_gcd(b,a%b,y,x),y-=a/b*x;
}
int C(ll n,ll m){
	if (n<m) return 0;
	if (n>=M) return C(n/M,m/M)*C(n%M,m%M)%M;
	int ans=1;
	for (int i=n-m+1;i<=n;i++) ans=ans*i%M;
	for (int i=2;i<=m;i++) ex_gcd(i,M,x,y),ans=ans*(x+M)%M;
	return ans;
}
int main(){
	scanf("%lld%lld",&n,&m);
	ex_gcd(n,M,x,y);
	printf("%d",((x+M)*C(n*m,n-1)+1)%M);
}

猜你喜欢

转载自blog.csdn.net/xumingyang0/article/details/83450594
今日推荐