This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//动态规划,不在乎过程,只在乎结果,后面依赖前面结果 | |
//最后一步:到结尾 | |
//子问题:目标是ryr形式,翻牌3次,dp[0]翻r,dp[1]翻y,dp[2]翻r | |
//状态转移方程: | |
// dp[0][i] = dp[0][i-1] + incRed | |
// dp[1][i] = Math.min(dp[0][i - 1], dp[1][i - 1]) + incYellow | |
// dp[2][i] = Math.min(dp[1][i - 1], dp[2][i - 1]) + incRed | |
//初始条件: | |
// dp[0][0] = leaves[0] === 'r' ? 0 : 1 | |
// dp[1][0] = Number.MAX_VALUE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//动态规划,不在乎过程,只在乎结果,后面依赖前面结果 | |
//最后一步:到结尾 | |
//子问题:目标是ryr形式,翻牌3次,dp[0]翻r,dp[1]翻y,dp[2]翻r | |
//状态转移方程: | |
// dp[0][i] = dp[0][i-1] + incRed | |
// dp[1][i] = Math.min(dp[0][i - 1], dp[1][i - 1]) + incYellow | |
// dp[2][i] = Math.min(dp[1][i - 1], dp[2][i - 1]) + incRed | |
//初始条件: | |
// dp[0][0] = leaves[0] === 'r' ? 0 : 1 | |
// dp[1][0] = Number.MAX_VALUE |