Contest problems codechef

https://www.codechef.com/SPGC2021/problems/SHA2101

Is this problem to be solved by dynammic programming

Yes you can do it using dp or even a simple pattern.
Here is the dp approach

int dp[1001] = {0};
dp[2] = 1, dp[1] = 1, dp[0]=1;
for(int i=3;i<=1000;i++){
    if(i%3 == 0)    dp[i] = min(dp[i-1], dp[i-2]);
    else if((i-1)%3 == 0)    dp[i] = min(dp[i-1], dp[i-3]);
    else dp[i] = min(dp[i-1], min(dp[i-2], dp[i-3]));
    dp[i]^=1;
}

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.