Submission #613843

#TimeUsernameProblemLanguageResultExecution timeMemory
6138432fat2codeKangaroo (CEOI16_kangaroo)C++17
0 / 100
1 ms340 KiB
#include "bits/stdc++.h" #define fr first #define sc second #define all(s) s.begin(), s.end() #define rc(s) return cout << s, 0 using namespace std; const int mod = 1e9 + 7; const int nmax = 2005; int n, s, t, dp[nmax][nmax]; int32_t main(){ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0); //freopen("input.in", "r", stdin); cin >> n >> s >> t; if(s > t) swap(s, t); dp[0][0] = 1; for(int i=1;i<n;i++){ for(int j=1;j<=n;j++){ if(i < s){ dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1] * ((j + 1) * j % mod) % mod) % mod; } else if(i == s){ dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % mod; } else if(i > s && i < t){ dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1] * (j * (j - 1) % mod) % mod + dp[i - 1][j + 1] * j % mod) % mod; } else if(i == t){ dp[i][j] = (dp[i - 1][j] + dp[i - 1][j + 1] * j % mod) % mod; } else{ dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j + 1] * ((j + 1) * j % mod) % mod) % mod; } } } cout << dp[n - 1][1] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...