poj 1671 Rhyme Schemes

这是一道对斯特林数的运用:s[n][k] = s[n-1][k-1] + k*[n-1][k];

View Code
#include<iostream>

#include<cstdio>

#include<cstdlib>

#include<algorithm>

#include<cmath>

#include<queue>

#include<set>

#include<map>

#include<cstring>

#include<vector>

#include<string>

#define LL long long

using 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;

}

 

你可能感兴趣的:(Scheme)