Submission #526318

#TimeUsernameProblemLanguageResultExecution timeMemory
526318Jeff12345121Kangaroo (CEOI16_kangaroo)C++14
100 / 100
29 ms22984 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;

#ifdef LOCAL
ifstream in("in.in");
ofstream out("out.out");
#else
#define in cin
#define out cout
#endif

const int nmax = 2005,mod = 1000000007;

int n,s,t;
int dp[nmax][nmax];
void addSelf(int &a, int b) {
    a = (a + b) % mod;
}
int32_t main() {
    in >> n >> s >> t;
    if (s > t) {
        swap(s,t);
    }

    dp[1][1] = 1;
    for (int i = 2; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            if (i != s && i != t) {
                addSelf(dp[i][j] , dp[i - 1][j - 1] * (j - (i > s) - (i > t)));
                addSelf(dp[i][j] , dp[i - 1][j + 1] * j);
            } else {
                addSelf(dp[i][j] , dp[i - 1][j - 1]); // we can make a new group with just i, or add this to the left-most
                addSelf(dp[i][j] , dp[i - 1][j]);
            }
        }
    }

    out << dp[n][1] << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...