Submission #1093144

#TimeUsernameProblemLanguageResultExecution timeMemory
1093144Zero_OPKangaroo (CEOI16_kangaroo)C++14
100 / 100
15 ms14212 KiB
#include "bits/stdc++.h" using namespace std; const int mod = 1e9 + 7; void add(int& a, int b){ a += b; if(a >= mod) a -= mod; } void sub(int& a, int b){ a -= b; if(a < 0) a += mod; } int mul(int a, int b){ return 1LL * a * b % mod; } const int MAX = 2e3 + 5; int n, s, t, dp[MAX][MAX]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> s >> t; dp[0][0] = 1; for(int i = 0; i < n; ++i){ for(int j = 0; j <= i; ++j){ if(!dp[i][j]) continue; if(i + 1 == s || i + 1 == t){ add(dp[i + 1][j], dp[i][j]); add(dp[i + 1][j + 1], dp[i][j]); } else{ add(dp[i + 1][j + 1], mul(dp[i][j], j - 1 + (i + 1 < s) + (i + 1 < t))); if(j > 1) add(dp[i + 1][j - 1], mul(dp[i][j], j - 1)); } } } cout << dp[n][1] << '\n'; 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...