HDOJ 题目4372 Count the Buildings(斯特林第一类数)

57 篇文章 1 订阅

Count the Buildings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 738    Accepted Submission(s): 246


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 first building and looking forward, and B buildings when you are behind the last building and looking backward. A building can be seen if the building is higher than any building between you and it.
Now, given N, F, B, your task is to figure out how many ways all the buildings can be.
 

Input
First line of the input is a single integer T (T<=100000), indicating there are T test cases followed.
Next T lines, each line consists of three integer N, F, B, (0<N, F, B<=2000) described above.
 

Output
For each case, you should output the number of ways mod 1000000007(1e9+7).
 

Sample Input
  
  
2 3 2 2 3 2 1
 

Sample Output
  
  
2 1
 

Source
 

Recommend
zhuyuanchen520   |   We have carefully selected several similar problems for you:   4059  1098  1130  1131  1134 
ac代码
#include<stdio.h>
#include<string.h>
#define mod 1000000007
__int64 s[2010][2010],c[2010][2010],n,f,b;
void fun()
{
    int i,j;
    for(i=0;i<2010;i++)
    {
        c[i][0]=1;
        c[i][i]=1;
        s[i][0]=0;
        s[i][i]=1;
        for(j=0;j<i;j++)
        {
            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
            s[i][j]=(s[i-1][j]*(i-1)%mod+s[i-1][j-1])%mod;
        }
    }
}
int main()
{
    int t;
    fun();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d%I64d",&n,&f,&b);
        printf("%I64d\n",c[b+f-2][f-1]*s[n-1][f+b-2]%mod);
    }
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值