摘要: 之前学习锁,用到了lock_guard,让我想起了自己智能指针部分还有所欠缺,故借机学习一波 **智能指针:**一个对于指针的封装,目的在于更好的管理内存,防止指针使用中的内存泄漏、二次释放等问题的产生。在C++的<memory>库中,有以下几种指针:auto_ptr、auto_ptr_ref、sh 阅读全文
posted @ 2022-03-02 23:12 fwx 阅读(104) 评论(0) 推荐(0)
摘要: 583. 两个字符串的删除操作 class Solution { public: int minDistance(string word1, string word2) { int len1 = word1.size(); int len2 = word2.size(); int dp[len1 + 阅读全文
posted @ 2022-03-02 22:48 fwx 阅读(33) 评论(0) 推荐(0)
摘要: 309. 最佳买卖股票时机含冷冻期 class Solution { public: int maxProfit(vector<int>& prices) { int p_len = prices.size(); int dp[p_len][3]; memset(dp, 0 ,sizeof(dp)) 阅读全文
posted @ 2022-03-02 22:45 fwx 阅读(30) 评论(0) 推荐(0)
摘要: class Solution { public: int findTargetSumWays(vector<int>& nums, int target) { int sum = target; for_each(begin(nums), end(nums), [&sum](int x){ sum 阅读全文
posted @ 2022-03-02 22:37 fwx 阅读(24) 评论(0) 推荐(0)
摘要: 416. 分割等和子集(背包) class Solution { public: // dp[i][j] 能获得的最大价值: // i --> 代表前i件商品 // j --> 能得到的重量j // 0/1背包状态转移方程: // dp[i][j] = max(dp[i-1][j-w[i]] + v 阅读全文
posted @ 2022-03-02 18:06 fwx 阅读(23) 评论(0) 推荐(0)
摘要: 状态转移方程: class Solution { public: int longestCommonSubsequence(string text1, string text2) { int len1 = text1.size(); int len2 = text2.size(); int dp[l 阅读全文
posted @ 2022-03-02 15:40 fwx 阅读(21) 评论(0) 推荐(0)
摘要: class Solution { public: int wiggleMaxLength(vector<int>& nums) { int len = nums.size(); if(len == 1) return 1; int up = 1; // key !!! int down = 1; / 阅读全文
posted @ 2022-03-02 15:35 fwx 阅读(28) 评论(0) 推荐(0)
摘要: 按照算法导论的说法,如果把每一个数对理解为一个活动的开始和结束时间,那么我们的目的是尽可能多的进行更多的活动。 此时对于贪心算法,我么直观上应该选择这样一个活动,选出它后剩下的资源应能被尽量多的其他任务所用。因此,应该选择最早结束的活动,因为他剩下的资源可供他之后尽量多的活动使用。这也是为什么要按照 阅读全文
posted @ 2022-03-02 12:49 fwx 阅读(33) 评论(0) 推荐(0)
摘要: 最长递增子序列 // 方法一:动态规划O(N^2) class Solution { public: int lengthOfLIS(vector<int>& nums) { int num_len = nums.size(); int dp[num_len]; dp[0] = 1; int res 阅读全文
posted @ 2022-03-02 12:27 fwx 阅读(21) 评论(0) 推荐(0)
摘要: 343. 整数拆分 class Solution { public: int integerBreak(int n) { if(n <= 2) return 1; int dp[n+1]; dp[1] = 1; dp[2] = 1; for(int i=3;i<=n;++i){ dp[i] = 1; 阅读全文
posted @ 2022-03-02 10:40 fwx 阅读(29) 评论(0) 推荐(0)
摘要: 64. 最小路径和 class Solution { public: int minPathSum(vector<vector<int>>& grid) { int len_x = grid.size(); int len_y = grid[0].size(); int dp[len_y]; dp[ 阅读全文
posted @ 2022-03-02 10:27 fwx 阅读(31) 评论(0) 推荐(0)
摘要: 【动态规划】198. 打家劫舍 213. 打家劫舍 II class Solution { public: int rob(vector<int>& nums) { int num_len = nums.size(); if(num_len == 1) return nums[0]; else if 阅读全文
posted @ 2022-03-02 10:10 fwx 阅读(51) 评论(0) 推荐(0)