Why is the condition like this?

i mean how he thought to add and multiply them , and why ???

image

plz explain by drawing a diagram or an example , without that its hard to understand

Can you please tell the time stamp, will be easier for me.

15:00 to 21:00 minutes is the time stamp

Okay, there are two things in it,

First that it is a 2000 rated question on CF. Even, I took over 30 minutes to come up with the solution. So, it is definitely hard, and hence, you 'll have to put some efforts to get the solution.

Second, it involves some math which is hard to explain (but I’ll try my best). And, much harder to tell “how to arrive at the following expression yourself”, because the answer to this is just practice.

Now, I am going to explain the question in next reply.

Let,

dp[i][0] = number of ways to form a group with the ith node and there is no black node (that is, all the nodes in that group are white).

dp[i][1] = number of ways to form a group with the ith node and there is exactly one black node (that is, all the nodes in that group are white, except one).

Now, let’s first see the case of black node:

ith node is black

dp[i][0] = 0 (as it is not possible that we have “a group with ith node and no node in it black”)
dp[i][1] = number of ways to form a group of only whites with its children (children of ith node), as we can’t take any other node with black color

ith node is white

dp[i][0] = number of ways to form a group of only whites with its children
dp[i][1] = number of ways to form a group with one black and rest all whites

I’ve written the logical thing right now, if you have any doubts in this ask me, else, I’ll proceed to mathematical part.

You need to be active??!!

Tell me if you get till here or I should explain more.