Problem 1108 D - Codeforces - using DP

For the problem Diverse Garlands, how to reconstruct the optimal string from the dp array?
My solution is as follows - Click here

Any help here please…

use an NX3 DP … n rows for each alphabet and 3 columns for R ,G, B … Now lets say 1st element is R … then fill Dp[0][0] as 1 and leave the other 2 columns of dp[0] as 0 and increament count by 1
now let’s say the next element is R again … We cant have that as next so you make the rest 2 values as count and increament it again …
Basically assign dp[i][x] = count if and only if dp[i-1][x] was 0 …
try this solution it should be very intuitive