Not easy series of (4)--Test groomTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 25588 Accepted Submission (s): 9358
Problem Description National Day, the provincial capital Hz just held a grand collective wedding, in order to make the wedding to enrich some, MC temporarily came up with an interesting program, called "Test Groom", the specific operation is this:
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).
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
22 23 2
Sample Output
13
Authorlcy
Source Recursive Solution topic exercise (for beginner)
Recommendlcy | We have carefully selected several similar problems for you:2045 2050 2046 2044 2047
#include <iostream> #include <algorithm> #include <stdio.h> #include <string.h> #include < Stdlib.h> #include <iomanip>using namespace std;long long int num[101];int n,m;int main () { int T; NUM[1] = 0; NUM[2] = 1; for (int i=3;i<=20;i++) { Num[i] = (i-1) * (Num[i-2] + num[i-1]); } scanf ("%d", &t); while (t--) { long long int sum = 1; scanf ("%d%d", &n,&m); for (int i=1;i<=m;i++) { sum *= (n+1-i); Sum/= i; } printf ("%lld\n", Sum*num[m]); } return 0;}
HDU 2049 Not Easy Series (4)--Test groom (wrong row)