제출 #1122402

#제출 시각아이디문제언어결과실행 시간메모리
1122402qrn캥거루 (CEOI16_kangaroo)C++14
100 / 100
30 ms31992 KiB
#include <bits/stdc++.h>
using namespace std;

#define SPEED ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define ALL(x) x.begin(), x.end()
#define intt long long
#define pb push_back
#define endl "\n"

const int mod = 1e9 + 7, inf = 1e9;

void solve() {
    intt n, cs, cf;
    cin >> n >> cs >> cf;
    vector<vector<intt>> dp(n + 1, vector<intt>(n + 1));
    dp[1][1] = 1;
    intt fixed = 0;
    for(int i = 1; i <= n; i++) {
        fixed += (i == cs || i == cf);
        for(int j = 1; j < i; j++) {
            if(i == cs || i == cf) {
                dp[i][j+1] += (dp[i-1][j]);
                dp[i][j+1] %= mod;
                dp[i][j] += (dp[i-1][j]);
                dp[i][j] %= mod;
            } else {
                dp[i][j+1] += (dp[i-1][j] * (j + 1 - fixed));
                dp[i][j+1] %= mod;
                dp[i][j-1] += (dp[i-1][j] * (j - 1));
                dp[i][j-1] %= mod;
            }
        }
    }
    cout << dp[n][1] << endl;
}

int main() {
    SPEED;
    intt tst = 1;
    // cin >> tst;
    while (tst--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...