会员
众包
新闻
博问
闪存
赞助商
HarmonyOS
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Danae丶
博客园
首页
新随笔
联系
订阅
管理
2021年9月17日
零钱兑换
摘要: 题源: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丶
阅读(56)
评论(0)
推荐(0)
2021年9月16日
整数拆分
摘要: 题源: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丶
阅读(72)
评论(0)
推荐(0)
2021年8月22日
最佳买卖股票时机含冷冻期
摘要: 题源: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丶
阅读(43)
评论(0)
推荐(0)
2021年8月20日
最长递增子序列
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/longest-increasing-subsequence/ 这类动态规划题目就是考虑目前和之前的大小关系 1 class Solution { 2 public: 3 int lengthOfLIS(
阅读全文
posted @ 2021-08-20 11:13 Danae丶
阅读(18)
评论(0)
推荐(0)
2021年8月18日
完全平方数
摘要: 题源: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丶
阅读(33)
评论(0)
推荐(0)
2021年8月16日
丑数II
摘要: 题源: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丶
阅读(15)
评论(0)
推荐(0)
2021年8月15日
最大正方形
摘要: 题源: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丶
阅读(57)
评论(0)
推荐(0)
2021年8月14日
打家劫舍
摘要: 题源: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丶
阅读(57)
评论(0)
推荐(0)
2021年8月13日
单词拆分
摘要: 题源:LeetCode 链接:https://leetcode-cn.com/problems/word-break/ 这道题目也是用到动态规划,同时考虑使用哈希表的数据结构。 其中check指的是dp[j]后的词是否在哈希表中出现,若出现则dp[i]为true 1 class Solution {
阅读全文
posted @ 2021-08-13 10:53 Danae丶
阅读(50)
评论(0)
推荐(0)
2021年8月12日
三角形最小路径和
摘要: 题源: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丶
阅读(46)
评论(0)
推荐(0)
下一页
公告