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 DEBUG false
using namespace std;
const int MAX_N = 2e3 + 10;
const int MOD = 1e9 + 7;
int dp[MAX_N][MAX_N];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, cs, cf;
cin >> N >> cs >> cf;
dp[1][1] = 1;
for(int i = 2; i <= N; i++) {
for(int j = 1; j <= N; j++) {
if(i == cs or i == cf) {
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
}
else {
int v = j - (i > cs) - (i > cf);
dp[i][j] = (dp[i][j] + 1ll*j * dp[i - 1][j + 1]) % MOD;
dp[i][j] = (dp[i][j] + 1ll*v * dp[i - 1][j - 1]) % MOD;
}
}
}
cout << dp[N][1];
return 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... |