제출 #592926

#제출 시각아이디문제언어결과실행 시간메모리
592926Tudy006Kangaroo (CEOI16_kangaroo)C++14
100 / 100
25 ms15964 KiB
#include <bits/stdc++.h>

using namespace std;

const int NMAX = 2000;
const int MOD = 1e9 + 7;

int dp[NMAX + 1][NMAX + 2];

int main() {
    int n, start, finish;
    cin >> n >> start >> finish;
    dp[0][1] = 1;
    for ( int i = 0; i < n; i ++ ) {
        for ( int j = 0; j <= n; j ++ ) {
            if ( i + 1 == start || i + 1 == finish ) {
                dp[i + 1][j] = ( dp[i + 1][j] + dp[i][j] ) % MOD;
                if ( j >= 1 ) dp[i + 1][j - 1] = ( dp[i + 1][j - 1] + dp[i][j] ) % MOD;
            } else {
                dp[i + 1][j + 1] = ( dp[i + 1][j + 1] + (long long)dp[i][j] * j ) % MOD;
                if ( j >= 1 ) dp[i + 1][j - 1] = ( dp[i + 1][j - 1] + (long long)dp[i][j] * ( j - ( i + 1 < start ) - ( i + 1 < finish ) ) ) % MOD;
            }
        }
    }
    cout << dp[n][0];
    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...