How to approach toward this codeforces Dynamic programming problem

Problem - 234C - Codeforces

I really don’t have no idea at all how to approach this problem