Submission #36731

# Submission time Handle Problem Language Result Execution time Memory
36731 2017-12-14T04:44:12 Z aome Kangaroo (CEOI16_kangaroo) C++14
0 / 100
0 ms 17880 KB
#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 = 0; 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 * (j - 1) / 2 % mod);
				add(f[i + 1][j + 1], 1LL * f[i][j] * (j + 1) % mod);
			}
		}
	}
	cout << f[n + 1][1];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17880 KB Output is correct
2 Incorrect 0 ms 17880 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17880 KB Output is correct
2 Incorrect 0 ms 17880 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17880 KB Output is correct
2 Incorrect 0 ms 17880 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17880 KB Output is correct
2 Incorrect 0 ms 17880 KB Output isn't correct