Hello, Can someone help me understand how the problem is solvable with dynamic programming ?
[G. Training Camp] ACM Arabella Collegiate Programming Contest 2015 http://codeforces.net/gym/100676
# | 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 | 151 |
Hello, Can someone help me understand how the problem is solvable with dynamic programming ?
[G. Training Camp] ACM Arabella Collegiate Programming Contest 2015 http://codeforces.net/gym/100676
Name |
---|
Do a standard bitmask DP with a loop from 1 to N inside where at every step you decide to try taking the ith item or not. Let's call that DP[msk].
Now it comes down to knowing whether you can choose the current item or not. ( You have taken all topics required for it).
Create a graph G where edges are reversed and mark roots as nodes with indegree of zero in the original graph. We can use a node in the first DP if we can start at it, and reach a root node from all our paths using only the nodes in our msk. This can be done with another DP in N * 2 ^N.
You should also handle cases with cycle since he didn't mention anything about it being a DAG, in these cases answer should be zero D:. ( You can't take items in cycles, so if you get rid of them you will end up with a DAG ).
This gets a runtime error because a parsing error that I'm too lazy to debug but I'm sure it will work, give a try.
Thank you for explaining the solution. Note: I solved it without checking if there is a cycle and got AC.