https://community.topcoder.com/stat?c=problem_statement&pm=1996&rd=4710
http://acmph.blogspot.com/2018/02/topcoder-srm-178-div-1-minipaint.html
https://github.com/darkzeroman/topcoder/blob/master/minipaint-java/MiniPaint.java
https://github.com/gabesoft/topc/blob/master/src.archive.1/dynamic/MiniPaint.java
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2010, TopCoder, Inc. All rights reserved.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
http://acmph.blogspot.com/2018/02/topcoder-srm-178-div-1-minipaint.html
First of all it must be clear that having a fixed number of strokes for each row, the problem can be solved independently for each row, so on a top level we have to decide how many strokes to assign to each row and tell them to solve themselves (paint themselves) and then we choose the best combination. So in order to solve the assignment problem we use dynamic programming.
int g(int row, int strokes)
This is the state of our outer DP, which tells if we have to solve rows in range [0...row] and only have strokes number of strokes left, what would be the minimum number of mispainted cells? So we can assign 0, 1, 2, ..., width assigns to the current row and solve g(row-1, strokes-k) which k is the number of strokes that we have assigned to the current row, in this case what would be the number of mispainted cells for this row? f(row, length-1, k) but what this means?
int f(int row, int idx, int strokes)
This is the state of our inner DP, which means we want to paint row of the picture in range [0...idx] and only have strokes number of strokes left. There are two options for us, first not paint cell at (row, idx), which means cost off(row, idx-1, strokes-1) + 1, or paint cells in range [k...idx] with cost of f(row, k-1, strokes-1) + numberOfCellsDifferent to cell at (row, idx).
Think about base cases yourself. (e.g. where row is -1 or strokes is equal to zero)
int g(int row, int strokes)
This is the state of our outer DP, which tells if we have to solve rows in range [0...row] and only have strokes number of strokes left, what would be the minimum number of mispainted cells? So we can assign 0, 1, 2, ..., width assigns to the current row and solve g(row-1, strokes-k) which k is the number of strokes that we have assigned to the current row, in this case what would be the number of mispainted cells for this row? f(row, length-1, k) but what this means?
int f(int row, int idx, int strokes)
This is the state of our inner DP, which means we want to paint row of the picture in range [0...idx] and only have strokes number of strokes left. There are two options for us, first not paint cell at (row, idx), which means cost off(row, idx-1, strokes-1) + 1, or paint cells in range [k...idx] with cost of f(row, k-1, strokes-1) + numberOfCellsDifferent to cell at (row, idx).
Think about base cases yourself. (e.g. where row is -1 or strokes is equal to zero)
https://github.com/darkzeroman/topcoder/blob/master/minipaint-java/MiniPaint.java
https://github.com/gabesoft/topc/blob/master/src.archive.1/dynamic/MiniPaint.java