Прошел первый этап XV Открытого Кубка по программированию. Как решать задачи А, Е, К?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Прошел первый этап XV Открытого Кубка по программированию. Как решать задачи А, Е, К?
Name |
---|
A Let's compute answer for vertex v. We can visit an associative vertex u like this:
Firstly go some steps using given edges, after that go using reversed edges.
So Dfs(vertex, isReversed) will work perfect here.
From isReversed = false we can go to isReversed = true, but not in other way.
Code
K, dynamic programming and
meet in the middledivide and conquerSorry that I am in english.
Can you explain in more details problem K?
K dp(i, j) — first i keys are assigned, and we have covered first j alphabets.
dp(i, j) = min dp(i-1, k) + cost(k+1, j)
Let's denote optK(i, j) — optimal k that gives for us minimum.
We can prove that, optK(i, j) <= optK(i, j + 1)
let's calculate recursively calc(i, l..r, optKl, optKr).
Firstly, we can calculate dp(i, mid), then recursively solve for
calc(i, l..mid, optKl, opt(i, mid)) and calc(i, mid+1..r, opt(i,mid), optKr)).
321E - Ciel and Gondolas also can be solved using this trick
Also, you can use convex hull optimization. Lets dp(i,j) — first i keys are assigned, and we have covered first j alphabets.
Code
K can be done by dp with a convex hull trick.
I would call it "divide and conquer" rather than "meet in the middle".
Indeed, thanks.