Git Product home page Git Product logo

test-the-groom's Introduction

Test-the-groom

Test the groom

Problem Description

国庆期间,省城刚刚举行了一场盛大的集体婚礼,为了使婚礼进行的丰富一些,司仪临时想出了有一个有意思的节目,叫做"考新郎",具体的操作是这样的:

首先,给每位新娘打扮得几乎一模一样,并盖上大大的红盖头随机坐成一排;

然后,让各位新郎寻找自己的新娘.每人只准找一个,并且不允许多人找一个.

最后,揭开盖头,如果找错了对象就要当众跪搓衣板...

看来做新郎也不是容易的事情...

假设一共有N对新婚夫妇,其中有M个新郎找错了新娘,求发生这种情况一共有多少种可能.

Input

输入数据的第一行是一个整数C,表示测试实例的个数,然后是C行数据,每行包含两个整数N和M(1<M<=N<=20)。

Output

对于每个测试实例,请输出一共有多少种发生这种情况的可能,每个实例的输出占一行。

Sample Input

2 2 2 3 2

Sample Output

1 3

错排类递推公式为:f(n)=(m-1)*[f(n-1)+f(n-2)],其中m表示错排的个数(即错排的新人对数),n表示全部的新人个数。

代码:

#include <stdio.h>

int main(void) {

int i, m, n;

__int64 a[21][2] = {{1,0},{1,0},{2,1},{6,2}};

for (i = 4; i < 21; i++)

{

    a[i][0] = i * a[i-1][0];
    
    a[i][1] = (i-1) * (a[i-1][1] + a[i-2][1]);
    
    
}

scanf("%d", &i);

while (i-- && scanf("%d%d", &n, &m))

    printf("%I64d\n", a[n][0]/a[m][0]/a[n-m][0]*a[m][1]);
    
return 0;

}

test-the-groom's People

Contributors

clustersdata avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.