제출 #903442

#제출 시각아이디문제언어결과실행 시간메모리
903442Spade1캥거루 (CEOI16_kangaroo)C++14
100 / 100
27 ms31756 KiB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll ll>
#define st first
#define nd second
#define pb push_back
using namespace std;

const int maxN = 2e3 + 2;
const int M = 1e9 + 7;

ll dp[maxN][maxN];

void solve() {
    int n, cf, cs, ct = 0; cin >> n >> cf >> cs;
    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        if (i == cf || i == cs) ct++;
        for (int j = 1; j <= n; ++j) {
            if (i == cf || i == cs)
                dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i-1][j-1]) % M;
            else {
                dp[i][j] = (dp[i][j] + (j-ct)*dp[i-1][j-1]) % M;
                dp[i][j] = (dp[i][j] + j*dp[i-1][j+1]) % M;
            }
        }
    }
    cout << dp[n][1] << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) 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...