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>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
const int N=2005,mod=1e9+7;
int dp[N][N];
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,s,t;
cin>>n>>s>>t;
dp[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(i==s or i==t)dp[i][j]=dp[i-1][j]+dp[i-1][j-1]%mod;
else{
int x=0;
if(i>s)x++;
if(i>t)x++;
dp[i][j]=dp[i-1][j+1]*j%mod;
dp[i][j]+=dp[i-1][j-1]*(j-x)%mod;
}
}
}
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... |