제출 #834331

#제출 시각아이디문제언어결과실행 시간메모리
834331GondozuKangaroo (CEOI16_kangaroo)C++14
100 / 100
32 ms31680 KiB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define Gondozu ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);

using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vpi = vector <pair<int, int>>;
using vvi = vector <vector<int>>;

const int OO = 1e9 + 5;
const int N = 2e3 + 5, MOD = 1e9+7;

int n, s, e;
ll dp[N][N];

ll add(ll a, ll b) {
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}
ll mul(ll a, ll b) { return a * b % MOD; }


void TC()
{
    cin >> n >> s >> e;

    dp[0][0] = 1;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            ll &cur = dp[i][j];
            if(i == s || i == e){
                cur = add(dp[i-1][j], dp[i-1][j-1]);
                continue;
            }

            cur = add(mul(dp[i-1][j+1], j), mul(dp[i-1][j-1], max(0,j - (i>s) - (i>e))));
        }
    }
    cout << dp[n][1];
}

int32_t main() {
    Gondozu
    int t = 1;
//    cin >> t;
    while (t--) {
        TC();
        cout << '\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...