hdu 3625 Examining the Rooms——第一类斯特林数

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625

n^2 求斯特林数就行。要减去的就是1号钥匙在1号房间的方案,即 s[ n-1 ][ m-1] 。

注意是 <=m 。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=25;
int T,n,m;ll jc[N],s[N][N];
void init()
{
  jc[1]=1;for(int i=2;i<=20;i++)jc[i]=jc[i-1]*i;
  s[0][0]=1;
  for(int i=1;i<=20;i++)
    for(int j=1;j<=i;j++)
      s[i][j]=s[i-1][j]*(i-1)+s[i-1][j-1];
}
int main()
{
  init();
  scanf("%d",&T);
  while(T--)
    {
      scanf("%d%d",&n,&m);
      ll ans=0;
      for(int i=1;i<=m;i++)ans+=s[n][i]-s[n-1][i-1];
      printf("%.4f\n",(double)ans/jc[n]);
    }
  return 0;
}

 

posted on 2018-12-04 23:10  Narh  阅读(126)  评论(0编辑  收藏  举报

导航