제출 #158089

#제출 시각아이디문제언어결과실행 시간메모리
158089solimm4sks캥거루 (CEOI16_kangaroo)C++14
100 / 100
36 ms16120 KiB
#include <bits/stdc++.h>
using namespace std;

int dp[2005][2005];
const int MOD = 1e9 + 7;

int 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 <= n; ++j){
            if(i == cs || i == cf){ ///must put this at beggining or end
                dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1]; ///(will link/wont link chain)
                dp[i][j] %= MOD;
            }else{
                dp[i][j] = (1LL * dp[i - 1][j + 1] * j) % MOD + (1LL * dp[i - 1][j - 1] * (j - (i > cs) - (i > cf))) % MOD; ///if i > cs I cant put it before cs, if i > cf then I cant put it after it
                dp[i][j] %= MOD;
            }
        }
    }

    cout << dp[n][1] << "\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...