摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/coin-change/ 代码: 1 class Solution { 2 public: 3 int coinChange(vector<int>& coins, int amount) { 4 vec 阅读全文
posted @ 2021-09-17 14:59 Danae丶 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 题源:Leetcode 链接:https://leetcode-cn.com/problems/integer-break/ 很显然,最少分成两个整数,所以有以下推导: dp[i] = max(j*(i-j),j*dp[i-j]) 代码如下: 1 class Solution { 2 public: 阅读全文
posted @ 2021-09-16 16:55 Danae丶 阅读(64) 评论(0) 推荐(0) 编辑
摘要: 题源:leetcode 链接:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-with-cooldown/ 比原来的那个最佳买卖股票时机II多了一个情况去进行dp,其他思路一样。 1 class Solution { 阅读全文
posted @ 2021-08-22 13:39 Danae丶 阅读(33) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/longest-increasing-subsequence/ 这类动态规划题目就是考虑目前和之前的大小关系 1 class Solution { 2 public: 3 int lengthOfLIS( 阅读全文
posted @ 2021-08-20 11:13 Danae丶 阅读(10) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/perfect-squares 一道比较简单的动态规划: 1 class Solution { 2 public: 3 int numSquares(int n) { 4 vector<int> f(n 阅读全文
posted @ 2021-08-18 19:22 Danae丶 阅读(28) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/ugly-number-ii/ 考虑使用dp 1 class Solution { 2 public: 3 int nthUglyNumber(int n) { 4 vector<int> dp(n + 阅读全文
posted @ 2021-08-16 13:23 Danae丶 阅读(8) 评论(0) 推荐(0) 编辑
摘要: 题源:Leetcode 链接:https://leetcode-cn.com/problems/maximal-square/ 1 class Solution { 2 public: 3 int maximalSquare(vector<vector<char>>& matrix) { 4 if 阅读全文
posted @ 2021-08-15 11:10 Danae丶 阅读(38) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/house-robber/ 这道题也是经典的dp类型的题目 1 class Solution { 2 public: 3 int rob(vector<int>& nums) { 4 int size = 阅读全文
posted @ 2021-08-14 10:47 Danae丶 阅读(39) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/word-break/ 这道题目也是用到动态规划,同时考虑使用哈希表的数据结构。 其中check指的是dp[j]后的词是否在哈希表中出现,若出现则dp[i]为true 1 class Solution { 阅读全文
posted @ 2021-08-13 10:53 Danae丶 阅读(44) 评论(0) 推荐(0) 编辑
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/triangle/ 这道题目使用动态规划解决。 1 class Solution { 2 public: 3 int minimumTotal(vector<vector<int>>& triangle) 阅读全文
posted @ 2021-08-12 09:10 Danae丶 阅读(34) 评论(0) 推荐(0) 编辑