pages:
- 1
abhishek SAYS
#include<iostream>
using namespace std;
#define p 1000000007
long ncr[101][101];
long dp[101][101];
long func(int n,int x) {
if(n<0||n<x)return 0;
if(n==x)return 1;
if(x==0)return 0;
if(dp[n][x]!=-1)return dp[n][x];
long ans=0;
return (dp[n][x]=(func(n-1,x-1)+(n-1)*func(n-1,x))%p);
}
int main() {
int t;
cin>>t;
for(int i=0;i<101;i++) {
ncr[i][0]=1;
for(int j=1;j<=i;j++)
ncr[i][j]=(ncr[i-1][j-1]+ncr[i-1][j])%p;
for(int j=i+1;j<101;j++)
ncr[i][j]=0;
}
for(int i=0;i<101;i++)
for(int j=0;j<101;j++)
dp[i][j]=-1;
for(int k=1;k<=t;k++) {
int n,l,r;
cin>>n>>l>>r;
cout<<"Case "<<k<<":"<<endl;
if(n<l||n<r||l<=0||r<=0){cout<<"0"<<endl;continue;}
long ans=0;
for(int i=l;i+r-1<=n;i++) {
long tm=(func(i-1,l-1)*func(n-i,r-1))%p;
tm=(tm*ncr[n-1][i-1])%p;
ans=(ans+tm)%p;
}
cout<<ans<<endl;
}
return 0;
}
Login please!
In order to post something you must login first. You can use the form in the top of this page.