HDU水题2049
此题主要是结合了错排和组合数两个要点,要注意的就是打表时,要开一个long long 数组,因为涉及到阶乘。
#define lcm(a, b) a / gcd(a, b) * b
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<set>
typedef long long ll;
using namespace std;
const ll M = 100000;
const int maxn = 105;
ll b[maxn], a[3];
long long dp[maxn];
double f[maxn];
bool st[M];
long long C(int n, int m) {
long long sum = 1;
int j = 1;
for (int i = n; i >= n - m + 1; i--) {
sum = sum * i / j;
j++;
}
return sum;
}
int main() {
int t;
scanf("%d", &t);
b[1] = 0;
b[2] = 1;
for (int i = 3; i <= 21; i++) {
b[i] = (i - 1) * (b[i - 1] + b[i-2]);
}
while (t--) {
int n, m;
scanf("%d%d", &n,&m);
//cout << b[m] * C(n, m) << endl;
printf("%lld\n", b[m]*C(n, m));
}
return 0;
}