Submission #770377

#TimeUsernameProblemLanguageResultExecution timeMemory
770377Sami_MassahKangaroo (CEOI16_kangaroo)C++17
100 / 100
138 ms126332 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2000 + 12, mod = 1e9 + 7; long long n, s, e, dp[maxn][maxn][4]; int main(){ cin >> n >> s >> e; if(1 == s){ dp[1][1][1] = 1; } else if(e == 1){ dp[1][1][2] = 1; } else{ dp[1][1][0] = 1; } for(int i = 1; i <= n; i++){ for(int j = 1; j <= n; j++) for(int c = 0; c < 4; c++){ // cout << i << ' ' << j << ' ' << c << ' ' << dp[i][j][c] << endl; dp[i][j][c] %= mod; if(i + 1 == s){ dp[i + 1][j][c | 1] += dp[i][j][c]; dp[i + 1][j + 1][c | 1] += dp[i][j][c]; } else if(i + 1 == e){ dp[i + 1][j][c | 2] += dp[i][j][c]; dp[i + 1][j + 1][c | 2] += dp[i][j][c]; } else{ int cnt = j + 1; if(c & 2) cnt -= 1; if(c & 1) cnt -= 1; dp[i + 1][j + 1][c] += dp[i][j][c] * cnt % mod; dp[i + 1][j - 1][c] += dp[i][j][c] * (j - 1) % mod; } } // cout << endl; } cout << dp[n][1][3] % mod << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...