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 X first
#define Y second
#define MP make_pair
#define ll long long
using namespace std;
const int N = 2003;
const ll mod = 1e9 + 7, INF = 1e18;
int n, cf, cs;
ll dp[N][N];
int main () {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> cs >> cf;
if(cs > cf)
swap(cf, cs);
dp[n + 1][0] = 1;
for(int i = n;i >= 1;i--){
for(int j = 0;j <= n - i + 1;j++){
if(i > cf){
dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * j * (j + 1)) % mod;
}
else if(i == cf){
dp[i][j] = (dp[i + 1][j] + dp[i + 1][j + 1] * (j + 1)) % mod;
}
else if(cs < i){
dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * (j + 1) * (j + 1)) % mod;
}
else if(cs == i){
dp[i][j] = (dp[i + 1][j] + dp[i + 1][j + 1] * (j + 1)) % mod;
}
else{
dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * (j + 2) * (j + 1)) % mod;
}
}
}
cout << dp[2][0];
}
# | 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... |