Submission #1118236

#TimeUsernameProblemLanguageResultExecution timeMemory
1118236vjudge1Kangaroo (CEOI16_kangaroo)C++17
100 / 100
31 ms31996 KiB
#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
#define itn int
#define INF 100000000
#define MOD 1000000007
#define MAX 103
#define endl "\n"
#define ff first
#define ss second
using namespace std;

int temp;
vector <vector <int>> dp(2005, vector <int>(2005));

signed main() {

	GOOD_LUCK

    int t;
	t = 1;
//	cin >> t;
    while (t--) {
        int n, a, b, cnt=0;
        cin >> n >> a >> b;
        dp[1][1] = 1;
        for (int i=1; i <= n; i++) {
        	if (i == a || i == b) cnt++;
        	for (int j=1; j <= i; j++) {
        		if (i == a || i == b) {
        			dp[i][j+1] += dp[i-1][j];
        			dp[i][j+1] %= MOD;
        			dp[i][j] += dp[i-1][j];
        			dp[i][j] %= MOD;
				}
				else {
					dp[i][j-1] += dp[i-1][j] * (j - 1);
					dp[i][j-1] %= MOD;
					dp[i][j+1] += dp[i-1][j] * (j + 1 - cnt);
					dp[i][j+1] %= MOD;
				}
			}
		}
		cout << dp[n][1] % MOD;
	}

    return 0;
}
// Problem B
// by Ekber_Ekber
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...