Submission #307370

#TimeUsernameProblemLanguageResultExecution timeMemory
307370jungsnowKangaroo (CEOI16_kangaroo)C++14
6 / 100
1 ms384 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int N = 2001; void add(int& a, int b) { a += b; while (a >= b) a -= mod; while (a < 0) a += mod; } void mul(int& a, int b) { a = 1ll * a * b % mod; } int st, en, n; int dp[N][N][4]; /// 0 - 00; 1 - 10, 2 - 01, 3 - 11; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("kangaroo.in", "r", stdin); // freopen("kangaroo.out", "w", stdout); cin>>n>>st>>en; dp[0][0][0] = 1; int cur = 0; for (int i = 0; i < n - 2; ++i) { ++cur; if (cur == st) ++cur; if (cur == en) ++cur; // cerr<<cur<<'\n'; for (int j = 0; j <= i; ++j) { for (int k = 0; k < 4; ++k) { if (dp[i][j][k] == 0) continue; for (int t = 0; t < 2; ++t) if ((k >> t & 1) == 0){ int m = (t == 0 ? st : en); if (cur > m && j > 0) add(dp[i + 1][j - 1][k | (1 << t)], 1ll * dp[i][j][k] * j % mod); else add(dp[i + 1][j][k | (1 << t)], dp[i][j][k]); } add(dp[i + 1][j + 1][k], dp[i][j][k]); if (j > 1) add(dp[i + 1][j - 1][k], 1ll * (dp[i][j][k] * j) % mod * (j - 1) % mod); } } } cout << dp[n - 2][0][3]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...