Student Attendance Record II


Hi. You insert a P before the LLL in order to make the f[n3] string rewardable. I don't understand this. If the f[n3] string "bleeding" into the L or LL of the LLL makes the f[n3] string unrewardable, then why doesn't the first of the four cases (LPL) have the same issue, where an f[n5] string ending in LL would also "bleed" into the last characters, creating LLLPL?

@elle First Fix 'P' at last position (P), this will result f[n1]. Now fix 'L' at the last position, out of all valid f[n1] strings, only strings ending with PLL should not be considered as it will lead to PLLL strings which is not valid. Thus it results in f[n1]f[n4] and total of 2f[n1]f[n4]. Please let me know if you still have some question?

Thanks for your reply. Why fix an additional P to make PLLL? Isn't LLLL also invalid? The final recurrence relation is absolutely correct, but I'm not sure this is the correct explanation. I can explain a simpler way to get to 2f[n1]f[n4] but first I would like to understand yours. By the way, that's a typo in the graphic, writing "N" for the right branch instead of "P", right?

@elle This is because, we need to consider only those strings which are rewardable at the length (n3) but become unrewardable at a length(n1)(for left branch ). Only the strings ending with a P at length (n3) and ending with PLL of the left branch at length (n1) follow this criteria. Could you please share your simpler explanation?

Right. So consider the 1st of the 4 branches: [n3]LPL. A string like PPPPPPPPPPPPPPPLLLPL would be rewardable at [n3] but fail at [n1], would it not? That was my original question: Under your approach, why doesn't the 1st branch get considered as a "rewardable at [n3] but unrewardable at [n1]" case? Maybe your criterion is more specific but not fully stated; I would like to understand that part.

The simpler way, IMHO, and compliments to N. Shade at math.stackexchange.com, is to consider the cases (a) P, (b) PL, and (c) PLL. A minute of thought will reveal that these are mutually exclusive. It's also realized that going further, e.g. (d) PLLL, becomes useless because the string will always be unrewardable. So the whole of f[n] may be summarized by (a) + (b) + (c), in other words, f[n] = f[n1] + f[n2] + f[n3]. This means also that f[n1] = f[n2] + f[n3] + f[n4]. If you subtract the latter from the former to cancel out the f[n2] and f[n3] cases, then you are left with f[n] = 2 f[n1]  f[n4].