제출 #558092

#제출 시각아이디문제언어결과실행 시간메모리
558092Alexandruabcde캥거루 (CEOI16_kangaroo)C++14
100 / 100
35 ms15948 KiB
#include <bits/stdc++.h>

using namespace std;

constexpr int NMAX = 2005;
constexpr int MOD = 1e9 + 7;

int N, cs, cf;
int dp[NMAX][NMAX];

void Add (int &x, int y) {
    x = x + y;
    if (x >= MOD) x -= MOD;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N >> cs >> cf;

    dp[1][1] = 1;

    for (int i = 1; i < N; ++ i ) {
        for (int j = 1; j <= N; ++ j ) {
            if (i + 1 == cs || i + 1 == cf) {
                Add(dp[i+1][j], dp[i][j]);
                Add(dp[i+1][j+1], dp[i][j]);
            }
            else {
                Add(dp[i+1][j-1], 1LL * (j-1) * dp[i][j] % MOD);
                Add(dp[i+1][j+1], 1LL * (j+1 - (i >= cs) - (i >= cf)) * dp[i][j] % 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...