제출 #1325768

#제출 시각아이디문제언어결과실행 시간메모리
1325768sh_qaxxorov_571캥거루 (CEOI16_kangaroo)C++20
100 / 100
16 ms23084 KiB
#include <iostream>
#include <vector>
using namespace std;
long long dp[2005][2005];
const int MOD = 1000000007;

int main() {
    int N, cs, cf;
    if (!(cin >> N >> cs >> cf)) return 0;

    dp[0][0] = 1;

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= i; j++) {
            if (i == cs || i == cf) {
                dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD;
            } else {
                long long choices_to_add = j - (i > cs) - (i > cf);
                long long add = (dp[i - 1][j - 1] * choices_to_add) % MOD;
                long long combine = (dp[i - 1][j + 1] * j) % MOD;

                dp[i][j] = (add + combine) % MOD;
            }
        }
    }
    cout << dp[N][1] << endl;

    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...