l*******0 发帖数: 95 | 2 My solution should be correct. It prints the followings when you run the
code
min cost = 2
B = 1 2 2 3
public class MinAdjustment {
public int[] adjust(int[] A, int target) {
// state: cost[i][v] - the total cost of changing A[i] to v, where v
belongs to [0, max]
// init: cost[0][v] = |A[0] - v|;
// function: cost[i][v] = min(cost[i-1][v - target ... v + target])
+ |A[i] - v|
// where v, v - target and v + target all belong to [0,
max]
... 阅读全帖 |
|