1 /*经典的错排公式*/
   2 #include <stdio.h>
   3 
   4 __int64 a[21];
   5 
   6 void init(){
   7     a[1] = 0;
   8     a[2] = 1;
   9     a[3] = 2;
  10     int i;
  11     for(i=4; i< 21; i++){
  12         a[i] = (i-1) * (a[i-1] + a[i-2]);
  13     }
  14 }
  15 
  16 int main(){
  17     init();
  18     int n;
  19     while(scanf("%d", &n)!=EOF){
  20         printf("%I64d\n", a[n]);
  21     }
  22 
  23     return 0;
  24 }

hdu1465 参考答案 (2008-09-25 18:51:27由218编辑)

ch3n2k.com | Copyright (c) 2004-2020 czk.