这题跟hdu 2049 差不多,那个是从N个中选M个,这个是从N个从选1,2,3.......N/2个,错排与组合.....
#include<stdio.h> long long num[28]; void chart( ) { num[0] = 1; num[1] = 0; num[2] = 1; for( int i = 3; i < 28; ++i ) num[i] = ( i - 1 )*( num[i-1] + num[i-2] ); } long long f( int n,int k ) { double sum = 1; for( int i = n,j = 1; j <= k; ++j,--i ) sum *= i,sum /=j; return ( long long )sum; } long long cal( int n ) { long long sum = 0; for( int i = 0; i <= n / 2; ++i ) sum += num[i] * f( n,i ); return sum; } int main( ) { chart( ); int n; while( scanf( "%d",&n ),n ) { printf( "%I64d\n",cal( n ) ); } return 0; }