2135: This is heaven!

Topic description

Maple was tired of typing code, so Maple ran to the cats to save himself.

Maple came to an empty room, next to the room is a room with many cats, there is a button in Maple's room, every time you press the button, there will be only one cat from the next room Run over to play with Maple, of course, when there is no cat in the next room, no cat will come running.

After Maple pressed the button a few times, he found that the cats running over were only white and yellow, and if it was assumed that the probability of the remaining cats in the next room was the same each time the button was pressed, then Maple began to think, if When there are n white cats and m yellow cats in the next room, when he presses the button k times, what is the probability that the number of white cats and the number of yellow cats are a and b respectively.

 

enter

The first line has an integer T, which means there are T groups of data (1<=T<=2000)

Each set of data has five integers n,m,k,a,b, where 0<=n,m,k,a,b<=10

 

output

For each set of data, the probability obtained is a fraction A/B (A<=B and AB is a coprime integer), and two integers A and B are output, separated by a space.

 

sample input

21 1 1 1 09 1 10 9 1

Sample output

1 21 1

hint

In particular, fractions with probability 0 are represented as 0/1.

source

#include<stdio.h>
long long  Ac(int a,int b)
{
	long long  i,j,sum=1;
	if(b>a)
		return 0;
	if(b==a)
		return 1;
		j=b;
	for(i=a;j>0;i--,j--)
		sum*=i;
	for(i=1;i<=b;i++)
		sum/=i;
	return sum;
}
long long gcd(int a,int b)
{
	long long t;
	while(b)
	{
		t=a%b;
		a=b;
		b=t;
	}
	return a;
}
intmain()
{
	long long  t,m,n,a,k,b,sum1,sum2,sum3,sum,s;
	while(scanf("%lld",&t)!=EOF)
	{
		while(t--)
		{
			scanf("%lld%lld%lld%lld%lld",&n,&m,&k,&a,&b);
		    if(a>n||b>m)
	        {
	            printf("0 1\n");
	            continue;
	        }
	        
	        if(k<a+b&&a+b==n+m)
	        {
	            printf("0 1\n");
	            continue;
	        }
	        
	        if(a+b<n+m&&a+b!=k)
	        {
	            printf("0 1\n");
	            continue;
	        }
			sum1=Ac(n,a);
			sum2=Ac(m,b);
			sum3=Ac(m+n,a+b);	
			sum=sum1*sum2;
			s=gcd(sum,sum3);
			sum/=s;
			sum3/=s;
			printf("%lld %lld\n",sum,sum3);
		}
	}
	return 0;
}


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324790865&siteId=291194637