求助!!为什么bottom从1开始加会有==0的情况?
查看原帖
求助!!为什么bottom从1开始加会有==0的情况?
352285
Titan_Hope楼主2020/7/16 18:40
/*
不懂什么数论,直接用组合数解答*/
#include<iostream>

using namespace std;
int zh(int n,int x);
int main(void)
{
	//输入:
	int n,m;
	cin>>n>>m;
	string s1,s2;//对输入错误的处理 
	int x;//输入这个人持有的牌的个数 
	long long sum=1;
	if(n>=m&&m>0)
	{
		for(int i=0;i<m;i++)
		{
			cin>>x;
			sum=sum*zh(n,x);
			n=n-x;
			if(i<m-1&&n==0)
			{
				sum=0;
				break;
			}
		} 

		cout<<sum%10007;
	}
//如果输入的m>n了就直接输出0	
	else if(cin>>s1>>s2)
	{
		cout<<0;
	}

	return 0;
}
//算组合数 
int zh(int n,int x)
{
	int top=1,bottom=1;
	for(int i=0 ; i<x ; i++)
	{
		//上面的分母 
		top = top*(n-i);
		bottom = bottom*(i+1);//分子 
		
	}
 	if(bottom>0)
		return top/bottom; //感觉bottom还有==0的时候?不写这个if else 就re ,而且为什么只有30分? 
 	else return 0;
}
2020/7/16 18:40
加载中...