제출 #1139241

#제출 시각아이디문제언어결과실행 시간메모리
1139241THXuan캥거루 (CEOI16_kangaroo)C++20
100 / 100
18 ms31816 KiB
// dp[i][j] = the number of ways if consider the first i-th element and divide it into j #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> #define INF 1e9 typedef long long ll; using namespace std; const ll MOD = 1e9 + 7; ll dp[2005][2005]; void solve() { int n, s, e; cin >> n >> s >> e; dp[1][1] = 1; for (int i = 2; i <= n; i++) { if (i != s && i != e) { for (int j = 1; j <= n; j++) dp[i][j] = (dp[i - 1][j + 1] * j + dp[i - 1][j - 1] * (j - (i > s) - (i > e))) % MOD; } else { for (int j = 1; j <= n; j++) { dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD; } } } cout << dp[n][1] % MOD << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1;// cin >> t; while (t--) solve(); 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...