제출 #443562

#제출 시각아이디문제언어결과실행 시간메모리
443562nafis_shifat캥거루 (CEOI16_kangaroo)C++14
100 / 100
32 ms31692 KiB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
using namespace std;
const int mxn=2e3+5;
const int inf=1e9;
const ll mod = 1e9 + 7;
int main() {

    int n,cf,cs;

    cin >> n >> cf >> cs;


    ll dp[n + 1][n + 1] = {};


    dp[1][1] = 1;
    int k = (1 == cs || 1 == cf);

    for(ll i = 2; i <= n; i++) {
        if(i == cf || i == cs) k++;
        for(ll j = 1; j <= i; j++) {
            if(i == cf || i == cs) {
                dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod;
                continue;
            }
            dp[i][j] = (j - k) * dp[i - 1][j - 1]  % mod;
            dp[i][j] += j * dp[i - 1][j + 1] % mod;
            dp[i][j] %= mod;
        }
    }

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