If we pick a number x, we need to pay $x, and we need to choose the max side of x's two sides for the next guess.
We iterate through 1 to n to get a minimum.
dp[i][j] means the minimum value of guessing from i to j, the return value is dp[1][n]
第二题 LC 343 Integer break
// 错误1: dp[i] = Math.max(dp[i], Math.max(x * dp[i - x], x * (i - x)));
写成了 dp[i] = Math.max(dp[i], Math.max(x * dp[n - x], x * (i - x)));
debug 了十分钟,还以为思路错了,写代码注意啊,这种小bug有时候很难发现。
256. Paint House
这题locked了,在lintcode做的。
这个题有点意思,根据现在颜色,选之前的屋子dp值比较低的不同颜色来更新。