Can someone explain how to approach solution for this problem(http://codeforces.net/contest/366/problem/C). Any help regarding solving 2d dp problems will be helpful. Any good problems for understanding 2d DP or tutorials will also be helpful. Thanks in advance.