hdu4372 第一类斯特林数

题意:N栋大楼,高度1~N,从前看到F栋大楼,从后看到B栋大楼,问方案数

思路:你看到的F栋并不是F栋,而是F组大楼中分别最高的那个

第N栋肯定能被看到,所以将N分为,F-1+B-1组 

每一组最高的放在最左面(其余看不到可以乱排)

每一组至少一个,比如有一组分到123三栋,

那么123,312,231只算312一种(最高放最左),但是312跟321算两种

不同N数分相同M组,轮换不同算两种,显然第一类斯特林数

分了F+B-2组后还得选F-1放在左边(让他们从低到高排)

注意:防RE,f+b-2>2000输出0w


#include<set>
#include<map>
#include<cmath>
#include<vector>
#include<string>
#include<ctype.h>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<iterator>
#include<algorithm>
#define ll long long
#define INF  0x3f3f3f3f
#define scann(d) scanf("%d",&d)
#define scanl(d) scanf("%I64d",&d)
using namespace  std;
const double eps = 1e-8;
const double PI = acos(-1.0);
const double e  = 2.718281828459;
const int N=200000;
const int mod=1e9+7;
inline  int sgn(double a);
inline  ll gcd(ll a,ll b);
inline  ll mod_pow(ll x,ll n,ll mod); 			//快速幂 余数

ll s1[2005][2005];
void initS()
{
	memset(s1,0,sizeof(s1));  
	s1[0][0]=1;
	for(int i=1; i<=2001; i++)
	{
		s1[i][0]=0;
		s1[i][i]=1;
		for(int j=1; j<=2001&&j<=i; j++)
		{
			s1[i][j]=(s1[i-1][j]%mod*(ll)(i-1)%mod)%mod+s1[i-1][j-1]%mod;
			s1[i][j]%=mod;
		}
	}
}
ll c[2005][2005];
void initC()
{
    memset(c,0,sizeof(c)); 
	c[0][0]=1;
	c[1][0]=1;
	c[1][1]=1;
	for(int i=1; i<=2001; i++)
	{
		c[i][0]=c[i][i]=1;
		for(int j=1; j<=i; j++)
		{
			c[i][j]=c[i-1][j-1]%mod+c[i-1][j]%mod;//递推公式,2000比较小还能用 mod可以不是质数
			c[i][j]%=mod;
		}
	}
}
int main()
{
	initS();
	initC();
	//cout<<s1[4][2]<<endl;
	int T;
	cin>>T;
	while(T--)
	{
		int n,f,b;ll ans=0;
		//cin>>n>>f>>b;//670ms
		scanf("%d%d%d",&n,&f,&b);//280ms
		if(f+b-2<=2000)
		 ans=(c[f+b-2][f-1]%mod)*(s1[n-1][f+b-2]%mod);
		ans%=mod;
		printf("%lld\n",ans);
	}
	return 0;
}


















inline int sgn(double a)
{
	return a < -eps ? -1 : a < eps ? 0 : 1;
}

inline ll gcd(ll a,ll b)
{
	return a==0?b:gcd(b%a,a);
}

ll mod_pow(ll x,ll n,ll mod)//快速幂 余数
{
	ll res=1;
	while(n>0)
	{
		if(n&1)//n的二进制最右位是1,即奇数
			res=res*x%mod;
		x=x*x%mod;
		n=n>>1;		 //相当于n/=2;
	}
	return res;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值