제출 #565689

#제출 시각아이디문제언어결과실행 시간메모리
565689piOOEKangaroo (CEOI16_kangaroo)C++17
100 / 100
15 ms14080 KiB
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define sz(x) ((int)size(x)) #define trace(x) cout << #x << ": " << (x) << endl; typedef long long ll; const int mod = 1'000'000'007, maxN = 2001; int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } int mul(int a, int b) { return a * (ll) b % mod; } int dp[maxN][maxN]; //dp[i][number of blocks] int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, S, T; cin >> N >> S >> T; dp[1][1] = 1; for (int i = 2; i <= N; ++i) { for (int j = 1; j <= i; ++j) { if (i == S || i == T) { dp[i][j] = add(dp[i - 1][j - 1], dp[i - 1][j]); } else { dp[i][j] = add(mul(dp[i - 1][j - 1], j - (S < i) - (T < i)), mul(dp[i - 1][j + 1], j)); } } } cout << dp[N][1]; 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...