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;
long long dp[2005][2005];
long long md=1e9+7;
int k;
int main(){
int n,st,en;
cin>>n>>st>>en;
if(st==en){
cout<<1;
}
dp[0][1]=1;
dp[1][1]=1;
for(int i=1;i<=n;i++){
if(i==st||i==en){
k++;
}
for(int j=1;j<=n;j++){
if(i==st||i==en){
dp[i][j-1]+=dp[i-1][j];
dp[i][j]+=dp[i-1][j];
dp[i][j]%=md;
dp[i][j-1]%=md;
}else{
dp[i][j+1]+=dp[i-1][j]*(j+1-k);
dp[i][j-1]+=dp[i-1][j]*(j-1);
dp[i][j+1]%=md;
dp[i][j-1]%=md;
}
}
}
cout<<dp[n][1];
// cout<<"\n"<<k;
}
# | 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... |