Submission #849655

#TimeUsernameProblemLanguageResultExecution timeMemory
849655thanh913Kangaroo (CEOI16_kangaroo)C++14
100 / 100
14 ms31836 KiB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
using ll = long long;

const int N = 2e3+5, mod = 1e9+7;

//--------------------------------------
int n, st, ed;
ll f[N][N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n >> st >> ed;
    f[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (i == st || i == ed) {
                f[i][j] = f[i-1][j-1] + f[i-1][j];
            }
            else {
                f[i][j] = f[i-1][j-1] * (j - (i > st) - (i > ed));
                f[i][j] += f[i-1][j+1] * j;
            }
            f[i][j] %= mod;
        }
    }
    cout << f[n][1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...