제출 #1118197

#제출 시각아이디문제언어결과실행 시간메모리
1118197vjudge1캥거루 (CEOI16_kangaroo)C++17
100 / 100
57 ms14204 KiB
#include <bits/stdc++.h>
///#define int long long 
#define endl '\n' 
#define fi first
#define se second
#define mp make_pair
#define pll pair<long long, long long>
#define mein ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
using namespace std; 
using ii = pair<int,int>;
using ll = long long;
const int mod = 1e9 + 7;
const int N = 2005;
inline void fmin(int &x, int y){if(x > y)x=y;}
inline void fmax(int &x, int y){if(x < y)x=y;}
inline void add(int &x, int y){if((x+=y) >= mod)x-=mod;}
int n, cs, cf;
int dp[N][N];
int main(){
    cin >> n >> cs >> cf;
    dp[0][0] = 1;
    for(int i = 1; i < n; i++){
        if(i == cs ||i== cf){
            for(int j = 0; j < i; j++)
                add(dp[i][j], dp[i-1][j]);
            for(int j = 0; j < i; j++)
                add(dp[i][j-1], dp[i-1][j] * 1ll * j % mod);
            }   else {
                for(int j = 0; j < i; j++){
                    if(j >= 2)
                        add(dp[i][j-1], dp[i-1][j] * 1ll * j % mod * 1ll * (j-1) % mod);
                    if(i >= cs)
                        add(dp[i][j-1],dp[i-1][j] * 1ll * j % mod);
                     if(i >= cf)
                        add(dp[i][j-1],dp[i-1][j] * 1ll * j % mod);
                    add(dp[i][j+1], dp[i-1][j]);
                }
            }
    }
    cout << dp[n-1][0] << 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...