Submission #164780

#TimeUsernameProblemLanguageResultExecution timeMemory
164780ttnhuy313Kangaroo (CEOI16_kangaroo)C++14
6 / 100
17 ms16120 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2005, MOD = 1e9 + 7; int n, s, t, memo[N][N]; void add(int &a, int b) { a = (a + b) % MOD; return; } int calc(int pos, int k) { if (pos == n + 1) return (k == 1); if (~memo[pos][k]) return memo[pos][k]; int ret = 0; if (pos == s) { add(ret, calc(pos + 1, k)); add(ret, calc(pos + 1, k + 1)); } else if (pos == t) { add(ret, calc(pos + 1, k)); add(ret, calc(pos + 1, k + 1)); } else { add(ret, calc(pos + 1, k + 1) * (k + 1 - (pos > s) - (pos > t))); if (k >= 2) add(ret, calc(pos + 1, k - 1) * (k - 1)); } return memo[pos][k] = ret; } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); memset(memo, -1, sizeof memo); cin >> n >> s >> t; cout << calc(1, 0) << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...