考新郎
1 #include <iostream> 2 using namespace std; 3 4 int main() 5 { 6 int n, m, i; 7 long long a[25], b[25]; 8 a[0] = 1; a[1] = 1, a[2] = 2; 9 for (i = 3; i < 21; i++) 10 a[i] = a[i - 1] * i; 11 b[0] = 0; 12 b[1] = 1; 13 b[2] = 1; 14 b[3] = 2; 15 for (i = 4; i < 21; i++) 16 b[i] = (i - 1)*(b[i - 1] + b[i - 2]); 17 while (cin >> n >> m) 18 { 19 cout << a[n] / a[m] / a[n - m] * b[m] << endl; 20 } 21 return 0; 22 }