[Hangdian 100 questions] recursive solution special exercises (For Beginner) 2049 exam groom _ part of the wrong arrangement problem

Problem Description
First, dress each bride almost exactly, and sit in a row with large red hijabs randomly;
Then, let the bridegrooms find their brides. Each person is allowed to find only one, and no one is allowed to find one.
Finally, lift the hijab, if you find the wrong object, you must kneel in public ...

It seems that being a groom is not easy ...

Suppose there are N newly-married couples, among them M grooms find the wrong bride, how many possibilities are there for this to happen.
 

Input
The first line of the input data is an integer C, indicating the number of test instances, and then the C line of data, each line contains two integers N and M (1 <M <= N <= 20).
 

Output
For each test instance, please output the total number of possible occurrences of this situation, and the output of each instance occupies one line.
#include <iostream>

using namespace std;

int main()
{
    int c,i,j;
    int m,n;
    long long sm [21]; // The result of misalignment of m elements
    long long a[21];
    sm[0]=1;
    sm[1]=0;
    a[0]=1;
    a[1]=1;
    for(j=2;j<21;j++){
        sm[j]=(j-1)*(sm[j-1]+sm[j-2]);
        a[j]=j*a[j-1];
    }

    cin>>c;
    for(i=0;i<c;i++){
        cin>>n>>m;
        cout<<sm[m]*(a[n]/a[m]/a[n-m])<<endl;
    }
    return 0;
}

【postscript】

1. The reason is very simple. The combination number C (n, m) multiplied by m elements is staggered, but infinite WA is a bit painful. .

Intelligent Recommendation

[Hangdian 100 questions] 2005 Experimental Class Short Semester Exam 2042 Not Easy Series Part Two

Problem Description As the old man Xu had no money, the toll collector took half of his sheep and hesitated after seeing the old man tears, and returned one to the old man. Coincidentally, for each to...

HDU - 2049 is not easy to series (4) - test groom (wrong formula) (day_7_I)

Not easy series (4) - test groom Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 50993 Accepted Submission(s): 18596 Problem Description During th...

hdu 2049 Series is not easy (4) - the groom wrong test row

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. http://xiang578.top/...

HDU 2049 test Groom (wrong title row + combinatorics)

Problem Description During the National Day, the provincial capital HZ just held a grand mass wedding, the wedding of the rich in order to make some temporary master of ceremonies has come up with an ...

HDU 2049 - is not easy Series (4) - test Groom (wrong row)

Not easy Series (4) - test Groom Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 46965    Accepted Subm...

More Recommendation

HDU Recursive Solution Special Exercise (For Beginner) Problem Solving Report

hdu 2044 Click to open the link a[0]=1;a[1]=1 a[i]=a[i-1]+a[i-2] Fibonacci hdu 2045 Click to open the link 1. The n-1 grid and the 1st grid have different colors a [i] = a [i-1] 2. The n-1 cell and th...

[Hangdian 100 questions] 2092 integer solution

Original title:http://acm.hdu.edu.cn/showproblem.php?pid=2092 Divided into five situations, a lot of duplicate code, too lazy to change...

Java written exam exercises wrong questions (two)

1. Which of the following descriptions of forward and redirect is correct (BCD)? A forward means that the server transfers control to another internal server object, and the new object is fully respon...

[Hangdian 100 questions] [wrong row] 2068 RPG staggered

Original title link:http://acm.hdu.edu.cn/showproblem.php?pid=2068 Reference 1: Staggered formula explanation: Reference 2: Title Code:...

【Hangdian 100 questions】 For Beginner 2047 Aniu's EOF Beef Skewers

Problem Description A Niu brought a piece of superior beef jerky from home and was going to engrave a string of length n consisting of only three characters "E" "O" "F" C...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top