HDU1465+递推
经典的信封装信问题
f[ n ] = ( n-1 ) * ( f[ n-1 ]+f[ n-2 ] )
1 #include<stdio.h> 2 #include<string.h> 3 #include<stdlib.h> 4 typedef long long int64; 5 const int maxn = 22; 6 int64 a[ maxn ]; 7 8 void init(){ 9 a[ 0 ] = a[ 1 ] = 0; 10 a[ 2 ] = 1; 11 for( int i=3;i<=20;i++ ){ 12 a[ i ] = ( i-1 )*(a[ i-2 ] + a[ i-1 ]); 13 } 14 return ; 15 } 16 17 int main(){ 18 init(); 19 int n; 20 while( scanf("%d",&n)==1 ){ 21 printf("%I64d\n",a[ n ]); 22 } 23 return 0; 24 }
keep moving...