제출 #598776

#제출 시각아이디문제언어결과실행 시간메모리
598776minhnguyent546캥거루 (CEOI16_kangaroo)C++17
100 / 100
23 ms16060 KiB
#include <bits/stdc++.h>
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define sqr(a) (1LL * (a) * (a))
using namespace std;

#ifdef LOCAL
#include <bug.h>
#else
#define mt(...)
#endif

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1000000007;
const int inf = 0x3f3f3f3f;

// https://oj.uz/problem/view/CEOI16_kangaroo
// https://github.com/stefdasca/CompetitiveProgramming/blob/master/CEOI/CEOI%2016-Kangaroo.cpp
// https://codeforces.com/blog/entry/47764?#comment-704139
//-----------------------------------------------------------------------//

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, s, e;
    cin >> n >> s >> e;
    vector<vector<int>> dp(n + 1, vector<int>(n + 1));
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            if (i == s || i == e) {
                dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
            }
            else {
                int a = 1LL * dp[i - 1][j + 1] * j % mod; // merge two components
                int subtract = 0;
                if (i > s) ++subtract;
                if (i > e) ++subtract;
                int b = 1LL * dp[i - 1][j - 1] * (j - subtract) % mod; // create new component
                dp[i][j] = a + b;
            }   
            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...