Submission #385215

#TimeUsernameProblemLanguageResultExecution timeMemory
385215pure_memKangaroo (CEOI16_kangaroo)C++14
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> #define X first #define Y second #define MP make_pair #define ll long long using namespace std; const int N = 2003; const ll mod = 1e9 + 7, INF = 1e18; int n, cf, cs; ll dp[N][N]; int main () { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> cs >> cf; if(cs > cf) swap(cf, cs); dp[n + 1][0] = 1; for(int i = n;i >= 1;i--){ for(int j = 0;j <= n - i + 1;j++){ if(i > cf){ dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * j * (j + 1)) % mod; } else if(i == cf){ dp[i][j] = (dp[i + 1][j] + dp[i + 1][j + 1] * (j + 1)) % mod; } else if(cs < i){ dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * (j + 1) * (j + 1)) % mod; } else if(cs == i){ dp[i][j] = (dp[i + 1][j] + dp[i + 1][j + 1] * (j + 1)) % mod; } else{ dp[i][j] = ((j ? dp[i + 1][j - 1]: 0) + dp[i + 1][j + 1] * (j + 2) * (j + 1)) % mod; } } } cout << dp[1][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...