HDU 3625 Examining the Rooms 第一类斯特林数

最多可以暴力打开k次 对于一个环暴力一次 n个数排成i个(i<=k)非空环排列的种数 另外第一扇门不能暴力打开 所以1不能独立成环

#include <cstdio>
#include <cstring>
using namespace std;
typedef __int64 LL;
LL dp[22][22];
LL f[22];
int main()
{
	dp[0][0] = 1;
	f[0] = 1;
	for(int i = 1; i <= 20; i++)
	{
		dp[i][i] = 1;
		dp[i][0] = 0;
		for(int j = 1; j < i; j++)
			dp[i][j] = dp[i-1][j-1] + dp[i-1][j]*(i-1);
		f[i] = f[i-1] * i;
	}
	int T;
	scanf("%d", &T);
	while(T--)
	{
		int n, k;
		scanf("%d %d", &n, &k);
		LL sum = 0;
		for(int i = 1; i <= k; i++)
			sum += dp[n][i] - dp[n-1][i-1];
		double ans = (double)sum / f[n];
		printf("%.4lf\n", ans);
	}
	return 0;
}
时间: 2024-08-28 21:37:53

HDU 3625 Examining the Rooms 第一类斯特林数的相关文章

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

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3625 学习斯特林数:https://blog.csdn.net/qq_33229466/article/details/75042895 https://www.cnblogs.com/gzy-cjoier/p/8426987.html http://www.cnblogs.com/zhouzhendong/p/Stirling-Number.html 关于这道题: 得到一把钥匙后,可以连续开的门与钥匙

HDU 3625 Examining the Rooms(第一类斯特林数)

题意:给你n扇门,然后可以开k次门,每次们后都有一把钥匙,不能开1号门,问最后打开一号门的概率是多少 思路:看大家说是裸的第一类斯特林数,我觉得有篇博客写的很好(传送门),这里采取的是博客里的第二种思路,感觉这种如果想到的话更容易理解,但是并没有遇到博客里说的g++会wa的情况 代码: #include <bits/stdc++.h> using namespace std; typedef long long LL; const int maxn=55; LL s1[maxn][maxn];

HDU 3625 Examining the Rooms

Problem Description A murder happened in the hotel. As the best detective in the town, you should examine all the N rooms of the hotel immediately. However, all the doors of the rooms are locked, and the keys are just locked in the rooms, what a trap

HDU 3625 Examining the Rooms:第一类stirling数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3625 题意: 有n个房间,每个房间里放着一把钥匙,对应能开1到n号房间的门. 除了1号门,你可以踹开任意一扇门(不用钥匙),但你最多只能踹k次. 问你能将所有门打开的概率. 题解: · P(打开所有门) = 能打开所有门的钥匙放置情况数 / 钥匙放置的总情况数 · 钥匙放置的总情况数 = n! 那么考虑下能打开所有门的钥匙放置情况数... 由于每个房间里有且只有一把钥匙,所以如果将每个房间连向房间内

hdu 3625 第一类斯特林数

题目链接:click here Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1146    Accepted Submission(s): 689 Problem Description A murder happened in the hotel. As the best detective

HDU3625(SummerTrainingDay05-N 第一类斯特林数)

Examining the Rooms Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1661    Accepted Submission(s): 1015 Problem Description A murder happened in the hotel. As the best detective in the town, yo

【2019雅礼集训】【第一类斯特林数】【NTT&amp;多项式】permutation

目录 题意 输入格式 输出格式 思路: 代码 题意 找有多少个长度为n的排列,使得从左往右数,有a个元素比之前的所有数字都大,从右往左数,有b个元素比之后的所有数字都大. n<=2*10^5,a,b<=n 输入格式 输入三个整数n,a,b. 输出格式 输出一个整数,表示答案. 思路: 这道题是真的神啊... 首先,根据官方题解的思路,首先有一个n^2的DP: 定义dp[i][j]表示一个长度为i的排列,从前往后数一共有j个数字大于所有排在它前面的数字. 首先有转移式: \[dp[i][j]=d

第一类斯特林数

第一类斯特林数大概是这样一个意思:首先从n排列中选出一个m圆排列,这个圆排列也可以理解为有一个位置元素固定的排列,其方案数显然为(m-1)!. 可以用来解决一下有特殊位置的计数问题. 例题 [FJOI2016]建筑师 首先找到最高的建筑作为分水岭后,剩下的位置可以如下划分成a-1+b-1个区间. 发现这a-1+b-1个区间第每一个都必须满足区间最大值放在最前面. 这个东西就可以用第一类斯特林数解决. https://www.cnblogs.com/zhouzhendong/p/Stirling-

CF960G(第一类斯特林数)

设\(f(i,j)\)为\(i\)个数的序列,有\(j\)个前缀最大值的方案数 我们考虑每次添一个最小数,则有:\(f(i,j)=f(i-1,j)+(i-1)*f(i-1,j-1)\),显然这是第一类斯特林数 从而我们得到一个朴素的答案:\[Ans=\sum\limits_{i=1}^{n}f_{i,a-1}×f_{n-1-i,b-1}×C_{n-1}^i\] 理解:枚举\(i+1\)为最大值添的位置,则已经限制了前缀最大值个数及后缀最大值个数,然后再乘上前半部分所填的数 观察\(f_{i,a-