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 ll long long
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 2005; /// mind this $$
const int MAX = 2e6 + 123;
const int BS = 61;
const ll inf = 1e17;
const int mod = 1e9 + 7;
ll dp[sz][sz];
void solve(){
ll n, st, ed, i, j;
cin >> n >> st >> ed;
dp[1][1] = 1;
for(i = 2; i <= n; i++){
for(j = 1; j <= i; j++){
if(i == st || i == ed){
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
}
else{
dp[i][j] = (dp[i][j] + (dp[i - 1][j - 1] * (j - (i > st) - (i > ed))) % mod) % mod;
dp[i][j] = (dp[i][j] + (dp[i - 1][j + 1] * j) % mod) % mod;
}
}
}
cout << dp[n][1] << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
*/
# | 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... |