Help in a DP problem

Правка en2, от harsh-apcr, 2024-03-02 22:07:15

Problem Link : https://codeforces.me/problemset/problem/1912/K

My approach :

$$$dp[i][xy] = $$$ # subsequences in $$$a_1 \ldots a_i$$$ with consecutive sum of 3 is divisible by 2 which ends with $$$x, y$$$.

$$$dp[i][xy] = $$$ if $$$y = a_i$$$ then $$$ dp[i-1][xy] $$$ (not choose $$$a_i$$$) + $$$dp[i-1][zx]$$$ (choose $$$a_i$$$) ($$$z$$$ here is $$$(x+y) \textrm{mod} 2)$$$ ; else $$$ dp[i-1][xy] $$$

Base case $$$dp[2][a_1 a_2] = 1$$$ (others are initialised to 0)

But I'm not really getting correct answer with this approach, I can't really see why this is wrong. Any help is appreciated

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский harsh-apcr 2024-03-02 22:08:10 64
en2 Английский harsh-apcr 2024-03-02 22:07:15 21
en1 Английский harsh-apcr 2024-03-02 22:06:27 570 Initial revision (published)