Submission #924880

#TimeUsernameProblemLanguageResultExecution timeMemory
924880GithubKangaroo (CEOI16_kangaroo)C++17
100 / 100
22 ms31888 KiB
#include <iostream> #include <vector> #include <queue> #include <cstring> #include <map> #include <climits> #include <set> #include <cmath> #include <algorithm> #include <stack> using namespace std; #define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define ll long long const ll MOD = 1e9+7, MAXN = 5*1e6+5; int main() { speedup int n, a, b; cin >> n >> a >> b; vector<vector<ll>> dp(n+1, vector<ll>(n+1)); dp[1][1] = 1; for (int i = 2; i <= n; i++){ for (int j = 1; j <= i; j++){ if (i == a || i == b){ dp[i][j] = (dp[i-1][j]+dp[i-1][j-1])%MOD; }else{ dp[i][j] = (dp[i-1][j+1]*j+dp[i-1][j-1]*(max(j-(i>a)-(i>b), 0)))%MOD; } } } if (dp[n][1] < 0){ dp[n][1] += MOD; } cout << dp[n][1] << endl; 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...