Not easy series of (4)--Test Groom Time limit:2000/1000ms (java/other) Memory limit:65536/32768k (Java/other) total submission (s): 6 Ac cepted Submission (s): 3Problem description During the National day, the provincial capital Hz just held a grand collective wedding, in order to make the wedding to enrich some, the MC temporarily came up with an interesting program, called "Test Groom", the specific operation is such :
First, dress each bride almost exactly the same, and cover the big red hijab randomly sit in a row;
Then, let the groom look for their bride. Each person is allowed to find only one, and does not allow many people to find one.
Finally, uncover the hijab, if you find the wrong object will be in public kneeling rubbing clothes board ...
It seems that being a groom is not an easy thing to do ...
Suppose there is a total of n pairs of newlyweds, of whom M-groom has found the wrong bride, and how many possibilities there are in this situation.
The first line of input data is an integer c, representing the number of test instances, followed by the C row of data, each containing two integers n and m (1<m<=n<=20). <= "div=" ">
Output for each test instance, print out the total number of possible scenarios in which this occurs, with one row for each instance output.
Sample Input
2 2 2 3 2
Sample Output
1 3
Authorlcy
Source Recursive Solution topic exercise (for beginner)
1#include <stdio.h>2__int64 sieve[Wuyi];3 4 intZuheshu (intMintN//number of combinations;5 {6__int64 i,j,total=1, sum=1;7 for(i=m,j=1; j<=n;j++,i--)8 {9Total*=i; sum*=J;Ten } One A returntotal/sum; - } - the intMain () - { - intI,m,n; sieve[1]=1; sieve[2]=1; sieve[3]=2; - for(i=4;i<Wuyi; i++) + { -sieve[i]= (I-1) * (sieve[i-1]+sieve[i-2]);//wrong row; + A } atscanf"%d",&i); - while(i--) - { -scanf"%d%d",&m,&n); - intTemp=zuheshu (m,m-n); - inprintf"%i64d\n", temp*sieve[n]); - } to return 0; +}
Hangzhou Electric 2049--Not Easy series of (4)--Test groom