poj 3088 Push Botton Lock

这题是一道斯特林数:

这里就是先从B选出n个数,再把n个数分成m堆(1~n),堆里面无序,堆有序;

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;

int sum( int n , int k )

{

    if( n ==1 && k == 1 ) return 1;

    if( n == 0 || k == 0 ) return 0;

    return sum( n -1 , k -1 ) + k*sum( n -1 , k );    

} 

void Init( int A[],LL ans[] )

{

   A[0] = 1LL;

   for( int i = 1 ;i < 12 ; i ++ )

        A[i] = A[i-1]*i;

   for( int k = 1 ; k <= 11 ; k ++ )

   {

       for( int i = 1 ; i <= k ; i++ )

           for( int j = 1; j <= i ; j ++ )

           {

               ans[k] += 1LL*sum( i , j )*(A[k]/(A[i]*A[k-i])*A[ j ]); 

           }

//       printf( "%I64d\n",ans[k] );

   }

}

int main(  )

{

    int cnt = 0,T,n;

    int A[12];

    LL ans[12]={0};

    Init( A ,ans);

    while( scanf( "%d",&T )==1 )

    {

        for( int i = 1 ; i <= T ; i ++ )

        {

            scanf( "%d",&n );

            

            printf( "%d %d %I64d\n",i,n,ans[n]);

       }

   }

   // system( "pause" );

    return 0;

}

你可能感兴趣的:(Lock)