Submission #153399

#TimeUsernameProblemLanguageResultExecution timeMemory
153399lyc캥거루 (CEOI16_kangaroo)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int MOD = 1e9 + 7;
const int MAXN = 2005;

int N, S, F;
int dp[MAXN][MAXN];

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N >> S >> F;

    dp[N+1][1] = 1;
    int done = 0;
    RFOR(i,N,1){
        FOR(j,1,i){
            if (i == S or i == F) dp[i][j] = (dp[i+1][j] + dp[i+1][j+1]) % MOD;
            else dp[i][j] = ((ll)dp[i+1][j-1] * (j-1) + (ll)dp[i+1][j+1] * (j+1 - done)) % MOD;
        }
        if (i == S or i == F) ++done;
    }

    cout << dp[2][1] << endl;
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...