This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int dp[2010][2010],M=1e9+7;
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,a,b;
cin>>n>>a>>b;
dp[0][0]=1;
if(a>b)swap(a,b);
for(int i=1;i<a;i++) for(int j=1;j<=i;j++)
dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1])*j%M;
for(int j=1;j<=a;j++)
dp[a][j]=(dp[a-1][j-1]+dp[a-1][j])%M;
for(int i=a;++i<b;) for(int j=1;j<=i;j++)
dp[i][j]=(dp[i-1][j-1]*(j-1)+dp[i-1][j+1]*j)%M;
for(int j=1;j<=a;j++)
dp[b][j]=(dp[b-1][j-1]+dp[b-1][j])%M;
for(int i=b;i++<n;) for(int j=1;j<=i;j++)
dp[i][j]=(dp[i-1][j-1]*max(0,j-2)+dp[i-1][j+1]*j)%M;
cout<<dp[n][1]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |