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 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.
Input
The first line of the 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, output the total number of possible occurrences of this situation, with one row for each instance output.
Sample Input
22 23 2
Sample Output
13 The problem is not difficult, but because of careless to do a long time the specific idea is to pick the total number of m pairs in n (using permutation combination knowledge) multiplied by m to select different total number of wrong selection method calculated by recursive formula can be obtained (recursive formula to follow the idea of the law can be obtained) f1=1f2=1f3=2fn= (n -1) *f (n-1) *f (n-2) The correct code is as follows
#include <iostream>using namespaceStd;__int64 s[ -],x,p,q;intFintMintN) {s[0]=1; s[1]=1; s[2]=1; s[3]=2; P=1; Q=1; for(inti=m;i>m-n;i--) p*=i; for(intI=1; i<=n;i++) q*=i; for(intI=4;i< +; i++) {S[i]= (I-1) * (s[i-2]+s[i-1]); } cout<<p/q*s[n]<<Endl; returns[n];}intMain () {intN; CIN>>N; while(n--){ intb; CIN>>a>>b; F (A, b); } return 0;}
which
Error because midway data is out of bounds and p,q is not reset!!!
Careless!!!!
V-Not Easy series of (4)--The groom (second season water)