hdu3625(第一类斯特林数)

与第二类有些区别! 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <sstream>
#include <iostream>
using namespace std;
#define INF 0x3fffffff

typedef long long int LL;
#define N 22

LL dp[N][N];
LL sum[N];

int main()
{
    //freopen("//home//chen//Desktop//ACM//in.text","r",stdin);
    //freopen("//home//chen//Desktop//ACM//out.text","w",stdout);
    dp[1][1]=1;
    sum[0]=1;
    for(int i=2;i<=20;i++)
    {
        for(int j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j-1]+(i-1)*dp[i-1][j];
        }
    }
    for(int i=1;i<=20;i++)
        sum[i]=sum[i-1]*i;
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,k;
        scanf("%d%d",&n,&k);
        LL ans=0;
        for(int i=1;i<=k;i++)
            ans+=dp[n][i];
        for(int i=1;i<k;i++)
            ans-=dp[n-1][i];
        printf("%.4lf\n",1.0*(double)ans/sum[n]);
    }
    return 0;
}

 

posted @ 2013-07-17 18:18  chenhuan001  阅读(233)  评论(0编辑  收藏  举报