Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16646 Accepted Submission(s):
6935
Input 輸入數據包含多個多個測試實例,每個測試實例占用一行,每行包含一個正整數n(1<n<=20),n表示8006的網友的人數。
Output 對於每行輸入請輸出可能的錯誤方式的數量,每個實例的輸出占用一行。
Sample Input 2 3
Sample Output 1 2 就是一個錯排,公式是f[n]=(n-1)*(f[n-1]+f[n-2]); 推理過程可點擊:錯排 轉載請注明出處:尋找&星空の孩子 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1465
1 #include<stdio.h>
2 #define LL long long
3 LL f[25];
4 void init()
5 {
6 f[0]=0;
7 f[1]=0;
8 f[2]=1;
9 for(int i=3;i<=20;i++)
10 {
11 f[i]=(i-1)*(f[i-1]+f[i-2]);
12 }
13 }
14 int main()
15 {
16 int n;
17 init();
18 while(scanf("%d",&n)!=EOF)
19 {
20 printf("%lld\n",f[n]);
21 }
22 return 0;
23 }