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 pii pair <int,int>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define pb push_back
#define int long long
using namespace std ;
const int maxn = 2020 , inf = 1e18 , mod = 1e9 + 7 ;
int dp[maxn][maxn] , a[maxn] ;
signed main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0) ;
int n , s , e ;
cin >> n >> s >> e ;
dp[0][0] = 1 ;
for(int i =1 ;i <= n ; i++){
for(int j = 1; j <= n ; j++){
int t = (s < i) + (e <i ) ;
if(i!=s && i!=e){
dp[i][j] = (dp[i-1][j-1] *(j-t) % mod + dp[i-1][j+1] * j % mod )%mod ;
continue ;
}
dp[i][j] = (dp[i-1][j-1] + dp[i-1][j])%mod ;
}
}
cout << dp[n][1] ;
}
/*
*/
# | 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... |