This is a homework problem. Let $A$ be an input binary matrix of size $2 \times n$, and $L$ an integer. The objective is to cover all 1s in $A$ with submatrices, such that we minimize the sum of the size of the submatrices (we consider the size of a matrix the product of its rows and columns) and we use no more than $L$ submatrices. For example, if $A$ is $$ 1 \quad 1 \quad 0 \quad 0 \quad 1 \quad 1\\ 0 \quad 1 \quad 1 \quad 0 \quad 0 \quad 0 $$ and $L = 2$, the optimal solution would be covering $A$ with 2 submatrices of sizes $2 \times 3$ and $1 \times 2$: $$ x \quad x \quad x \quad 0 \quad x \quad x\\ x \quad x \quad x \quad 0 \quad 0 \quad 0 $$ in this case the output of an algorithm solving this problem should be $8$ (the sum of the sizes of the submatrices: $2\cdot 3 + 1 \cdot 2$), and $2$ (which means that we used 2 submatrices).
I've come up with a partial solution using dynamic programming, but it is so long that I doubt it is correct. In summary, suppose that we start to analyze the input array from the first column until the $k$-th column. Let $C_{OPT}(k)$ and $M_{OPT}(k)$ be the optimal solutions at the $k$-th column. If $M_{OPT} = L$ then we have two analyze whether the previous submatrix used covers the $(k-1)$-th column or not, and then observe how many 1s there are at the $k$-th column. Based on that, the recursive relationships between $C_{OPT}(k)$ and $C_{OPT}(k-1)$ can be written. However, I haven't figured out yet how to analyze the case where $M_{OPT} < L$.
Is my approach correct so far? Or is there a better way to solve this problem?