hdu 4372 第一类stirling数的应用/。。。好题


 1 /**
2 大意: 给定一系列楼房,都在一条水平线上,高度从1到n,从左侧看能看到f个, 从右侧看,能看到b个,问有多少种这样的序列。。
3 思路: 因为肯定能看到最高的,,那我们先假定最高的楼房位置确定,那么在其左边还有f-1个能看见,在其右边还有b-1个,能看见。。所以可以这样将题目转化: 将除最高楼之外的n-1个楼,分成f-1+b-1 组,在最高楼左边f-1 组,在其右边b-1组,那么分成f-1+b-1 组 就是第一类Stirling数。s[n-1][f-1+b-1]。。左边f-1 组,在其右边b-1组,就是将这f-1+b-1 组,组合c(f-1+b-1,f-1)
4 **/
5
6 #include <iostream>
7
8 using namespace std;
9 const long long mod = 1000000007;
10 long long c[2010][2010];
11 long long s[2010][2010];
12
13 void init(){
14 c[0][0] =1;
15 for(int i=1;i<=2000;i++){
16 c[i][0] = c[i][i] =1;
17 for(int j=1;j<i;j++){
18 c[i][j] = (c[i-1][j]+c[i-1][j-1])%mod;
19 }
20 }
21
22 for(int i=1;i<=2000;i++){
23 s[i][0] =0;
24 s[i][i] =1;
25 for(int j=1;j<i;j++)
26 s[i][j] = (s[i-1][j-1]+(s[i-1][j]*(i-1))%mod)%mod;
27 }
28
29 }
30
31 int main()
32 {
33 init();
34 int t;
35 cin>>t;
36 while(t--){
37 int n,f,b;
38 cin>>n>>f>>b;
39 long long res =0;
40 if(f+b-1<=2000)
41 res = (s[n-1][f+b-2]*c[f+b-2][f-1])%mod;
42 else
43 res =0;
44 cout<<res<<endl;
45 }
46 return 0;
47 }

hdu 4372 第一类stirling数的应用/。。。好题

时间: 2024-08-20 15:09:22

hdu 4372 第一类stirling数的应用/。。。好题的相关文章

hdu 4372 第一类斯特林数

#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <cmath> #include <cstring> #include <stack> #include <set> #include <map> #include <vector> using namespace st

HDU 4372 Count the Buildings:第一类Stirling数

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看可以看到b栋楼,并且高的楼会挡住低的楼. 问你这些楼有多少种排列方法. 题解: 由于高的楼会挡住低的楼,所以这些楼首先会被划分成f+b-2个区域(除去中间最高的楼),并且左边有f-1个,右边有b-1个. 对于一个区域(假设在左边),这个区域由若干栋楼组成,并且最高的楼一定在最左边. 那么,由一个区域

HDU 3625 Examining the Rooms:第一类stirling数

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

hdu 3625 第一类striling 数

1 /** 2 第一类Stirling数是有正负的,其绝对值是包含n个元素的集合分作k个环排列的方法数目. 3 递推公式为, 4 S(n,0) = 0, S(1,1) = 1. 5 S(n+1,k) = S(n,k-1) + nS(n,k). 6 7 大意: 有n个房间,n把钥匙,钥匙在房间中,问: 在最多破坏k个门的情况下,问有多少种方法,可以将所有的门打开,注意,不能破坏第一个门 8 9 思路: 即是将n个元素分成m个环,得排列方式..除掉第一个元素独立成环的方式 10 可以得出,这是第一类

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

HDU4372-Count the Buildings(第一类Stirling数+组合计数)

Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 171 Problem Description There are N buildings standing in a straight line in the City, numbere

Luogu4609 FJOI2016 建筑师 第一类Stirling数

题目传送门 题意:给出$N$个高度从$1$到$N$的建筑,问有多少种从左往右摆放这些建筑的方法,使得从左往右看能看到$A$个建筑,从右往左看能看到$B$个建筑.$N \leq 5 \times 10^4 , A,B \leq 100$ 第一次看到第一类$Stirling$数有用emmm 考虑将某种方案中最高的建筑拿出来,将分成的两半中可以看得见的与被它挡住的建筑分成一个部分,如下 绿色的当然是最高的,剩下的两个部分分成了1,2,3三个部分.可以知道我们总共需要$A+B-2$这样的部分,而其中$A

HDU 4372 Count the Buildings(组合数学-斯特林数,组合数学-排列组合)

Count the Buildings Problem Description There are N buildings standing in a straight line in the City, numbered from 1 to N. The heights of all the buildings are distinct and between 1 and N. You can see F buildings when you standing in front of the

[组合数学] 第一类,第二类Stirling数,Bell数

一.第二类Stirling数 定理:第二类Stirling数S(p,k)计数的是把p元素集合划分到k个不可区分的盒子里且没有空盒子的划分个数. 证明:元素在拿些盒子并不重要,唯一重要的是各个盒子里装的是什么,而不管哪个盒子装了什么. 递推公式有:S(p,p)=1 (p>=0)         S(p,0)=0  (p>=1)         S(p,k)=k*S(p-1,k)+S(p-1,k-1)   (1<=k<=p-1) .考虑将前p个正整数,1,2,.....p的集合作为要被