ps:长度长到我不想说....WA了无数次...25的阶乘就爆炸...
代码:
#include "stdio.h" #define LL long long LL fac(long long a); LL dp[25]; LL fac1(LL a,LL b); int main(){ LL i,n,s; LL k,sum; dp[0]=0; dp[1]=1; for(i=2;i<20;i++) dp[i]=i*(dp[i-2]+dp[i-1]); while(~scanf("%I64d",&n) && n){ sum=0; k=n/2; if(n%2==1) k++; while(n-k>=2){ sum+=fac1(n,n-k)*dp[n-k-1]; k++; } printf("%I64d\n",sum+1); } return 0; } LL fac(long long a){ int i; LL sum=1; for(i=1;i<=a;i++){ sum*=i; } return sum; } LL fac1(LL a,LL b){ long long i,k,t,sum,sum1; k=a-b; if(k>b){ t=k; k=b; b=t; } sum=1; for(i=a;i>b;i--){ sum*=i; } sum1=fac(k); return sum/sum1; }