Can someone help how to do this problem. The editorial is a bit unclear to me. I am finding it difficult to make transitions between the dp states. Thanks in advance!
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
Can someone help how to do this problem. The editorial is a bit unclear to me. I am finding it difficult to make transitions between the dp states. Thanks in advance!
Name |
---|
Guys, please help. I know knapsack dp, which I think will be used in this, but I don't have much experience in dp on trees problems.
Given a tree with $$$n$$$ vertices, each vertex has a value assigned to it- either $$$0$$$ or $$$1$$$. Find the number of sets of nodes (modulo $$$10^9+7$$$), such that the set is connected, and the sum of values of all nodes in the set is equal to $$$K$$$.
$$$(N<=5*10^4, K<=100)$$$
In my solution i have used these two concepts for transition:-
1.when you have root R with value C, X ways to get value A in a subtree rooted at left son of R, and Y ways to get value B in subtree rooted at right son of R, it gives you X*Y ways to get value A+B+C in subtree rooted at R(from editorial). Above example is just for two childs but you can extend this for >2 number of childs as well.
2.While solving "subset sum problem with linear space" we traverse from backward in dp to avoid multiple counting of same value.You can use same concept here.
link of "subset sum problem with linear space" video editorial :- https://www.youtube.com/watch?v=-httet0UVUU&t=1s link of my solution with comment :- https://ideone.com/Fplthb