http://codeforces.com/contest/1257/problem/D
Dp simple question
Forwarding a blog
https://www.cnblogs.com/QingyuYYYYY/p/11863747.html