【第一类斯特林数】HDU_4372_ Count the Buildings

来源:互联网 发布:csol辅助源码 编辑:程序博客网 时间:2024/04/28 11:43

Count the Buildings

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


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
23 2 23 2 1
 

Sample Output
21
 

Source
2012 Multi-University Training Contest 8
 

Recommend
zhuyuanchen520
#include <bits/stdc++.h>using namespace std;typedef long long LL;const int maxn=2005;const int mod=1e9+7;LL dp[maxn][maxn],c[maxn][maxn];void Init(int n,int k){    c[0][0]=1;    for(int i=1;i<=n;i++){        c[i][0]=1;         for(int j=1;j<=i;j++)            c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;    }    for(int i=0;i<=n;i++)        dp[0][i]=0;    dp[1][1]=1;    for(int i=2;i<=n;i++)        for(int j=1;j<=i;j++)            dp[i][j]=(dp[i-1][j-1]%mod+(i-1)%mod*dp[i-1][j]%mod)%mod;}int main(){    int t,N,F,B;    Init(2000,2000);    scanf("%d",&t);    while(t--){        scanf("%d%d%d",&N,&F,&B);        if(F+B-1>N){            puts("0");            continue;        }        LL ans=dp[N-1][F-1+B-1]*c[F-1+B-1][F-1]%mod;        printf("%I64d\n",ans);    }    return 0;}

阅读全文
0 0
原创粉丝点击