Hey Codeforces community,
I'm currently trying to solve problem 2069C from a recent Codeforces round and am exploring a dynamic programming approach for it. However, I'm struggling to implement it efficiently.
Here's what I have understood so far: Problem link -> 2069C - Beautiful Sequence A brute force solution seems infeasible due to [mention constraints]. I believe DP can be applied by but i am new to dp , so i am not getting how to think help
The idea is that we maintain three states say a1,a2,a3 the state a1 says that how many 1s are there till now where you can start your sequence with ( like in permutation and combination we study during 12th class either we start with this 1 or some other 1 and so we increase value of a1 by 1 as soon as we encounter a 1. the the state a2 states that how many combinations(of type 1 2222...) we can have before we end at a 3 now when you encounter a 2 in array you have two choice either use it or not use it and since a2 is essentialy storing number of ways till the last encountered 2 you multiply a2 by 2 to account for these two choices,but its also possible that you may start a sequence with this 2 and for that you will add a1 to a2 since these much 1s are available (i mean this is state definition for a1) so transition for a2 is given as a2=2*a2+a1 and when you reach 3 the choice is either you can end your sequence or not at this 3 for that you just update a3 as a3+=a2 ,and thus a3 comes out to be final answer. all in all think of solving a sub problem and states such that its easy to transit from one state to another.
you can refer to this} solution for recursive implementation and this for iterative implementation, idea in both of them is same as said by HashRash786
very thanks bhai