首页 > 其他 > 详细

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

时间:2018-12-05 01:37:12      阅读:233      评论:0      收藏:0      [点我收藏+]

题目: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;
}

 

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

原文:https://www.cnblogs.com/Narh/p/10068268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!