This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#include <iostream>
using namespace std;
typedef long long LL;
LL C(int a, int b) {
LL sum1 = 1, sum2 = 1;
for (int i = b + 1; i <= a; i++) sum1 *= i;
for (int i = 1; i <= a - b; i++) sum2 *= i;
return sum1 / sum2;
}
int main() {
LL f[21] = {0, 0, 1}; //这个初始化很牛B的样子,放过头雁打二雁,而且f[1]=0,f[2]=1
//错排公式,预处理
for (int i = 3; i < 21; i++) f[i] = (i - 1) * (f[i - 1] + f[i - 2]);
int T;
cin >> T;
while (T--) {
int n, m;
cin >> n >> m;
cout << C(n, m) * f[m] << endl;
return 0;