Submission #1059318

#TimeUsernameProblemLanguageResultExecution timeMemory
1059318TAhmed33Kangaroo (CEOI16_kangaroo)C++98
100 / 100
14 ms16016 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; int add (int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } int sub (int a, int b) { a -= b; if (a < 0) a += MOD; return a; } int mul (int a, int b) { return (a * 1ll * b) % MOD; } typedef long long ll; int dp[2003][2003], n, s, t; void solve () { cin >> n >> s >> t; dp[1][1] = 1; for (int i = 2; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == s || i == t) { dp[i][j] = add(dp[i - 1][j - 1], dp[i - 1][j]); } else { dp[i][j] = mul(dp[i - 1][j + 1], j); dp[i][j] = add(dp[i][j], mul(dp[i - 1][j - 1], j - (i > s) - (i > t))); } } } cout << dp[n][1] << '\n'; } signed main () { ios::sync_with_stdio(0); cin.tie(0); int tc = 1; //cin >> tc; while (tc--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...