제출 #1354545

#제출 시각아이디문제언어결과실행 시간메모리
1354545uranhishig캥거루 (CEOI16_kangaroo)C++20
100 / 100
12 ms23036 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int mod = 1e9 + 7;
const int maxn = 2005;

int dp[maxn][maxn];

signed main(){
    int n, cs, cf;
    cin >> n >> cs >> cf;
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= i; j++) {
            if (i == cs || i == cf) {
                dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
            } 
            else {
                int x = j - (i > cs) - (i > cf);
                int y = (dp[i - 1][j - 1] * x) % mod;
                int z = (dp[i - 1][j + 1] * j) % mod;
                dp[i][j] = (y + z) % mod;
            }
        }
    }
    cout << dp[n][1] << endl;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…