제출 #36732

#제출 시각아이디문제언어결과실행 시간메모리
36732aomeKangaroo (CEOI16_kangaroo)C++14
100 / 100
19 ms17880 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 2005;
const int mod = 1e9 + 7;

int n, st, ed;
int f[N][N];

void add(int &x, int y) {
	x = (x + y) >= mod ? x + y - mod : x + y;
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> st >> ed;
	f[1][0] = 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= i; ++j) {
			if (!f[i][j]) continue;
			if (i == st || i == ed) {
				if (j) add(f[i + 1][j], f[i][j]);
				add(f[i + 1][j + 1], f[i][j]);
			}
			else {
				if (j >= 2) add(f[i + 1][j - 1], 1LL * f[i][j] * (j - 1) % mod);
				int k = j - (i > st) - (i > ed) + 1;
				if (k > 0) add(f[i + 1][j + 1], 1LL * f[i][j] * k % mod);
			}
		}
	}
	cout << f[n + 1][1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...