摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/interleaving-string/ 这道题目可以考虑使用动态规划去完成 我们可以找到他的状态转移方程: 其中这个p为i+j-1。 代码实现如下: 1 class Solution { 2 publi 阅读全文
posted @ 2021-08-11 16:53 Danae丶 阅读(45) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/decode-ways 这也是一道动态规划的题目,注意f(x)和f(x-1)、f(x-2)的关系 1 class Solution { 2 public: 3 int numDecodings(strin 阅读全文
posted @ 2021-08-10 10:43 Danae丶 阅读(49) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/minimum-path-sum/ 还是一道经典的动态规划题 1 class Solution { 2 public: 3 int minPathSum(vector<vector<int>>& grid 阅读全文
posted @ 2021-08-09 09:18 Danae丶 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/unique-paths-ii/ 其实和上一个随笔中的不同路径一样,只是多了个障碍物,多了个判断的过程。 1 class Solution { 2 public: 3 int uniquePathsWit 阅读全文
posted @ 2021-08-08 09:02 Danae丶 阅读(18) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/unique-paths/ 一道动态规划题,维护一个m*n的数组即可 1 class Solution { 2 public: 3 int uniquePaths(int m, int n) { 4 ve 阅读全文
posted @ 2021-08-06 12:36 Danae丶 阅读(19) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/jump-game-ii/ 这次讨论两种解法,一个dp一个贪心 贪心的方法: 1 class Solution { 2 public: 3 int jump(vector<int>& nums) { 4 阅读全文
posted @ 2021-08-03 16:03 Danae丶 阅读(34) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/longest-palindromic-substring/solution/zui-chang-hui-wen-zi-chuan-by-leetcode-solution/ 动态规划经典题 首先,每一个 阅读全文
posted @ 2021-08-03 09:35 Danae丶 阅读(25) 评论(0) 推荐(0) 编辑
摘要: 尝试了一下按照类型刷题,确实比乱刷会好一点 做完了力扣的十几个简单难度的dp,后面开始做中等难度了 还是代码写的太少了,数组的操作都需要上网查一下 阅读全文
posted @ 2021-07-31 15:54 Danae丶 阅读(15) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/n-th-tribonacci-number/ 最简单的动态规划 1 class Solution { 2 public: 3 int tribonacci(int n) { 4 if(n==0) ret 阅读全文
posted @ 2021-07-31 15:37 Danae丶 阅读(24) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/divisor-game/ 一开始就想到了数学方法,即return (n%2==0) 这里还有个动态规划的方法: 1 class Solution { 2 public: 3 bool divisorGa 阅读全文
posted @ 2021-07-30 11:03 Danae丶 阅读(36) 评论(0) 推荐(0) 编辑