Submission #1294221

#TimeUsernameProblemLanguageResultExecution timeMemory
1294221orucKangaroo (CEOI16_kangaroo)C++20
100 / 100
39 ms31788 KiB
#include <bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define vpii vector<pii>
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int N = 2005;
const int M = 1000000007;
ll dp[N][N];

void solve(){
    ll n,cs,cf,a = 0;
    cin >> n >> cs >> cf;
    dp[1][1] = 1;
    for(int i = 1; i <= n; i++){
        if(i == cs || i == cf) a++;
        for(int j = 1; j <= n; j++){
            if(i == cs || i == cf){
                dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % M;
                dp[i][j] = (dp[i][j] + dp[i-1][j]) % M;
            }
            else{
                dp[i][j] = (dp[i][j] + (dp[i-1][j-1] * (j-a)) % M)%M;
                dp[i][j] = (dp[i][j] + (dp[i-1][j+1] * j) % M)%M;

            }
        }
    }
    cout << dp[n][1] << endl;
}

signed main(){
    fast;
    ll t = 1;
    //cin >> t;
    while(t--) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...