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 | 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 | 160 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | Dominater069 | 154 |
8 | awoo | 154 |
10 | luogu_official | 150 |
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