本文共 774 字,大约阅读时间需要 2 分钟。
这是一道对斯特林数的运用:s[n][k] = s[n-1][k-1] + k*[n-1][k];
#include #include #include #include #include #include #include #include #include #include #include #define LL long longusing namespace std;double c[124][124];void Init( ){ c[0][0] = 1.0; for( int i = 1 ; i <=100; i ++ ) for( int j = 0 ; j <=i ; j ++ ) { if( j==0 ) c[i][j] = 0; else c[i][j] = c[i-1][j-1] + 1.0*j*c[i-1][j]; } }int main( ){ Init(); int n; while( scanf( "%d",&n ),n ) { double ans=0.0; for( int i = 0 ; i <= n ; i ++ ) ans += c[n][i]; printf( "%d %.0f\n",n,ans ); } //system( "pause" ); return 0;}
转载于:https://www.cnblogs.com/bo-tao/archive/2012/08/13/2635845.html