[Zzulioj 2135] This is heaven !, Zzulioj2135 heaven

Source: Internet
Author: User

[Zzulioj 2135] This is heaven !, Zzulioj2135 heaven

Consider whether the current situation is feasible or not:

If a> n or B> m is absolutely unavailable, the probability is 0;

When a + B <m + n, k must be equal to a + B; otherwise, the probability is 0;

When a + B = m + n, k> = a + n; otherwise, the probability is 0;

The next step is to calculate a probability. Considering that the order in which Cats come does not affect the answer, you can directly use the classical summary model, that is, to find the number of feasible solutions divided by the total number of solutions.

The number of feasible solutions is to select a from n and multiply the number of B from m. The total number of solutions is to select a + B from m + n. That is, C (n, a) * C (m, B)/C (n + m, a + B ).

Because the data is small, you can use the recursive formula of the combination number to find the answer, and then use it as the denominator of the numerator.

 

Description

He got tired of coding the Maple, so Maple ran to find the cats and cats to save themselves.

Maple comes to an empty room. Next to the room is a room with many cats and cats. There is a button in the room of Maple, each time you press the button, there will be only one cat and cat running from the room next to them to seek for Maple. Of course, when there is no cat in the room next door, there will not be a cat running.

After Maple presses the button several times, it is found that only the white and yellow cat colors are used. If the probability of the remaining cat running next to the room is the same, then Maple began to think, if there were n white cats and m yellow cats in the next room, when he pressed the k button, the number of white cats and the number of yellow cats that run is the probability of a and B respectively.

 

 

Input

The first row has an integer T, indicating that there are T groups of data (1 <= T <= 2000)

Each group of data has five integers: n, m, k, a, and B, where 0 <= n, m, k, a, B <= 10

 

 

Output

For each group of data, the probability is A fraction A/B (A <= B and AB is An interlace integer). Two integers A and B are output, separated by A space.

 

 

Sample Input2 1 1 1 1 0 9 1 10 9 1 Sample Output1 2 1 1 HINT

In particular, the score representation with a probability of 0 is 0/1.

 

 1 #include <iostream> 2 #include<string> 3 #include<cstring> 4 #include<vector> 5 #include<set> 6 #include<map> 7 #include<stack> 8 #include<queue> 9 #include<list>10 #include<cmath>11 #include<algorithm>12 #include<cstdio>13 #include <bitset>14 #include <climits>15 #include <time.h>16 #include<iomanip>17 #define INF 0x3f3f3f3f18 using namespace std;19 #define ll long long20 21 ll C(int num1,int num2)22 {23     if(num2==0) return 1;24 25     ll res1 = 1;26     ll res2 = 1;27     for(int i=1;i<=num2;i++)28     {29         res1*=(num1-i+1);30         res2*=i;31     }32     return res1/res2;33 }34 35 36 int main()37 {38     //freopen("D://in.txt","r",stdin);39     //freopen("D://out.txt","w",stdout);40     int T;41     scanf("%d",&T);42     while(T--)43     {44         int n,m,k,a,b;45         scanf("%d%d%d%d%d",&n,&m,&k,&a,&b);46         if(a>n||b>m)47         {48             printf("0 1\n");49             continue;50         }51         if(a+b<n+m&&k!=a+b)52         {53             printf("0 1\n");54             continue;55         }56         if(a+b==n+m&&k<a+b)57         {58             printf("0 1\n");59             continue;60         }61         ll res1 = C(n,a)*C(m,b);62         ll res2 = C(n+m,a+b);63 64         ll g = __gcd(res1,res2);65         res1/=g;66         res2/=g;67         printf("%lld %lld\n",res1,res2);68     }69     return 0;70 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.