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 <iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const int oo = 2e3+7;
int n, s, e;
ll dp[oo][oo];
ll gdp(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
dp[i][j] = 0;
bool ee = i == s || i == e;
if (j > 1)
dp[i][j] += (ee ? 1 : (j - (i>=s) - (i>=e))) * gdp(i-1,j-1);
dp[i][j] %= mod;
dp[i][j] += (ee ? 1 : j) * gdp(i-1,(ee ? j : j+1));
dp[i][j] %= mod;
return dp[i][j];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> s >> e;
for (int i = 1; i <= n; i++) for (int j = 0; j <= n; j++) dp[i][j] = -1;
dp[1][1] = 1;
cout << gdp(n, 1) << endl;
}
# | 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... |