
LeetCode
不哭的超人
愿你孤独的努力终有回报,愿你前行的路上有人相伴。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Paint House
题目: There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same原创 2020-05-22 18:24:46 · 438 阅读 · 0 评论 -
55. 跳跃游戏
题目: 跳跃游戏 题解: 1、确定状态。假设第i为倒数倒数第二个,下一个就是直接跳n-1,并且所有的子问题都是这样。对于第i个假如能达到n-1,那么应该满足n-1-i<=a[i], 2、转移方程。上面方程已经得出来了,要求满足a[i]也能到达并且n-1-i<=a[i],那么就可以到达n。 3、初始条件和边界情况。对于这题边界不存在负数情况,所以不需要考虑。 4、计算顺序。如果从后往前,但是前面的答案没有的出来,所以不可能。顺序应该是从前往后。 class Solution { publi原创 2020-05-21 23:02:37 · 228 阅读 · 0 评论 -
零钱兑换
题目:零钱兑换 基础DP,解决DP问题分为四个步骤。 1、确定状态。要明白dp[i]或者dp[i][j]代表什么含义,本题的dp[i]表示到达i元所需要的最小数量货币的个数。确定状态需要有两个意识:最后一步、子问题。假设最后一枚硬币是c,倒数第二枚硬币为c1,那么求的dp[n] = min(dp[n-c]+1),c的值可能有多步,对于子问题dp[n-c] = min(dp[n-c-c1]+1)。 2、转移方程 由第一部的分析已经算出方程了,dp[n] = min(dp[n-c]+1) 3、初始条件和边界情况原创 2020-05-21 21:43:01 · 176 阅读 · 0 评论