hdu2049

来源:互联网 发布:java date setmonth 编辑:程序博客网 时间:2024/06/09 19:22

/*
  Description:是2048的加强版
  HDU__ACM 2049  不容易系列之(4)——考新郎
  http://acm.hdu.edu.cn/showproblem.php?pid=2049
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>

using namespace std;

long long c[25];

void InitJc()
{
   int i = 2; 
   c[0] = c[1] = 1;
   for(; i <= 20; ++i)
     c[i] = c[i-1]*i;
}

long long f(int n)
{
    if(n == 1)
      return 0;
    if(n == 2)
     return  1;
    return (n-1)*( f(n-1) + f(n-2) );
}
int main()
{
  int iCase; 
  int m, n;
  long long s;
  long long t ;
  scanf("%d", &iCase);
  InitJc();
  while( iCase-- ){
     scanf("%d%d", &n, &m);   
     s = f(m);/*m个完全错排的方法*/
     t = c[n]/(c[n-m]*c[m]);
     cout<<s*t<<endl;
  } 
  ///system("pause");
  return 0;
}

本文出自 “东方快翔” 博客,请务必保留此出处http://hustluy.blog.51cto.com/1792080/607329