题意:题目:
就是给你N个房间,然后每个房间1把钥匙,你最初手里没有任何钥匙,要靠破门而入!这里只有第一个房间不能破门进去,其他都可以,
就是给你N个房间,然后每个房间1把钥匙,你最初手里没有任何钥匙,要靠破门而入!这里只有第一个房间不能破门进去,其他都可以,
给你房间数N,和最多能破门的个数,让你求能全部把房间打开的概率!
解析: 赤裸裸的斯特林数啊!!
#include <iostream>
#include <stdio.h>
using namespace std;
const int A = 21;
long long ans[A][A],f[A];
int main()
{
int t,n,k;
ans[1][1] = 1;
f[0] = f[1] = 1;
for (int i = 2; i < A; i++)
{
for (int j = 1; j <= i; j++)
ans[i][j] = ans[i-1][j-1] + (i-1)*ans[i-1][j];
f[i] = f[i-1]*i;
}
cin >> t;
while (t-- && cin >> n >> k)
{
long long sum = 0;
for (int i = 1; i <= k; i++)
sum += ans[n][i] - ans[n-1][i-1];
printf("%.4lf\n",(double)sum/f[n]);
}
return 0;
}