标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 16634 Accepted Submission(s):
6928
2 3
1 2
//错排+预处理;
此题用到的公式是:f(n)=(n-1)*(f(n-1)+f(n-2));
其递推公式是:f(n)=n!(1-1/1!+1/2!-1/3!+1/4!+....................+(-1)^n*1/n!);
1 #include<stdio.h> 2 long long sieve[25]; 3 int main() 4 { 5 int i,n; 6 sieve[1]=0; sieve[2]=1; 7 for(i=3;i<21;i++) 8 sieve[i]=(i-1)*(sieve[i-1]+sieve[i-2]); 9 while(~scanf("%d",&n)) 10 { 11 printf("%lld\n",sieve[n]); 12 } 13 return 0; 14 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4575941.html