Submission #954800

#TimeUsernameProblemLanguageResultExecution timeMemory
954800DragosC1Kangaroo (CEOI16_kangaroo)C++17
100 / 100
35 ms16084 KiB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1000000007;

int dp[2005][2005];

int main() {    
    int n, start, finish;
    cin >> n >> start >> finish;
    dp[0][0] = 1;
    bool has_start = 0;
    bool has_end = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            if (i == start || i == finish) {
                dp[i][j] = (1LL * dp[i][j] + dp[i - 1][j] + dp[i - 1][j - 1]) % MOD;
                if (i == start)
                    has_start = 1;
                if (i == finish)
                    has_end = 1;
            }
            else {
                dp[i][j] = (1LL * dp[i][j] + 1LL * (j - has_start - has_end) * dp[i - 1][j - 1] % MOD) % MOD;
                dp[i][j] = (1LL * dp[i][j] + 1LL * j * dp[i - 1][j + 1] % MOD) % MOD;
            }
        }
    cout << dp[n][1] << '\n';
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...