发邮件

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 //错排问题,直接用公式
 5 //(n-1)*(f(n-1) + f(n-2))
 6 
 7 long long f(int n){
 8     if (n == 1)
 9         return 0;
10     if (n == 2)
11         return 1;
12     return (n - 1)*(f(n - 1) + f(n - 2));
13 }
14 
15 int main(){
16     int n;
17     while (cin >> n){
18         long long ans = f(n);
19         cout << ans << endl;
20     }
21     //system("pause");
22     return 0;
23 }
原文地址:https://www.cnblogs.com/ouyang_wsgwz/p/8511262.html