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 fr first
#define sc second
#define all(s) s.begin(), s.end()
#define rc(s) return cout << s, 0
using namespace std;
const int mod = 1e9 + 7;
const int nmax = 2005;
int n, s, t, dp[nmax][nmax];
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
//freopen("input.in", "r", stdin);
cin >> n >> s >> t;
dp[0][0] = 1;
if(s > t) swap(s, t);
for(int i=1;i<=n-1;i++){
for(int j=1;j<=i;j++){
if(i < s){
dp[i][j] = (dp[i - 1][j + 1] * ((j + 1) * j / 2 % mod) % mod + dp[i - 1][j - 1]) % mod;
}
else if(i == s){
dp[i][j] = (dp[i - 1][j] * j % mod + dp[i - 1][j - 1]) % mod;
}
else if(i > s && i < t){
dp[i][j] = (dp[i - 1][j + 1] * (j * (j - 1) / 2 % mod) % mod + dp[i - 1][j + 1] * j % mod) % mod;
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
}
else if(i == t){
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j] * (j - 1) % mod) % mod;
}
else{
dp[i][j] = (dp[i - 1][j + 1] * ((j + 1) * j / 2 % mod) % mod + dp[i - 1][j - 1]) % mod;
}
}
}
if(t == n){
cout << dp[n - 1][1] << '\n';
}
else{
cout << dp[n - 1][2] << '\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... |