摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/fibonacci-number/ 最基础的动态规划: 1 class Solution { 2 public: 3 int fib(int n) { 4 if (n < 2) { 5 return n; 阅读全文
posted @ 2021-07-30 10:59 Danae丶 阅读(56) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/min-cost-climbing-stairs/ 一道经典的动态规划题 1 class Solution { 2 public: 3 int minCostClimbingStairs(vector<i 阅读全文
posted @ 2021-07-29 17:59 Danae丶 阅读(39) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/is-subsequence/ 使用双指针法很简单,而且运行效率也很高。这里不贴代码了,学习一下动态规划的解法; 1 //dp解法 2 bool isSubsequence(string s, strin 阅读全文
posted @ 2021-07-28 14:39 Danae丶 阅读(60) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/counting-bits/ 这里还是使用动态规划去做,考虑到每隔2^n,结果加一,则可用动态规划。 1 class Solution { 2 public: 3 vector<int> countBit 阅读全文
posted @ 2021-07-28 14:14 Danae丶 阅读(56) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-ii/ 动态规划 考虑当天有股票和没有股票两种情况进行讨论: dp[i][0]=max{dp[i−1][0],dp[i−1][1]+pric 阅读全文
posted @ 2021-07-28 10:38 Danae丶 阅读(40) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/ 采用动态规划 dp[i]=max(dp[i−1],prices[i]−minprice) 1 class Solution { 2 pub 阅读全文
posted @ 2021-07-28 10:02 Danae丶 阅读(34) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/pascals-triangle/ 数学方法这里不赘述,这里写一下动态规划的转移方程 dp[i][j] = dp[i-1][j-1] + dp[i-1][j] 阅读全文
posted @ 2021-07-26 19:48 Danae丶 阅读(23) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/climbing-stairs/ 这也是道简单的动态规划题,状态转移方程为:f(x) = f(x-1)+f(x-2) 1 class Solution { 2 public: 3 int climbSta 阅读全文
posted @ 2021-07-26 11:01 Danae丶 阅读(48) 评论(0) 推荐(0)
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/maximum-subarray/solution/zui-da-zi-xu-he-by-leetcode-solution/ 一道简单的动态规划题 1 class Solution { 2 public 阅读全文
posted @ 2021-07-25 20:36 Danae丶 阅读(26) 评论(0) 推荐(0)
摘要: https://blog.csdn.net/sinat_36413257/article/details/98495962 阅读全文
posted @ 2021-07-25 16:44 Danae丶 阅读(13) 评论(0) 推荐(0)