随笔分类 -  Week8 动态规划

摘要:1 class Solution 2 { 3 public: 4 //完全背包问题 5 int change(int amount, vector<int>& coins) 6 { 7 vector<int>dp(amount + 1,0); 8 dp[0] = 1; 9 for(int i = 0 阅读全文
posted @ 2020-04-16 14:53 Jinxiaobo0509 阅读(131) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int minDistance(string word1, string word2) 5 { 6 int m = word1.size(); 7 int n = word2.size(); 8 9 vector<vector<int 阅读全文
posted @ 2020-04-16 10:36 Jinxiaobo0509 阅读(112) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int rob(vector<int>& nums) 5 { 6 if(nums.size() == 0) return 0; 7 if(nums.size() == 1) return nums[0]; 8 if(nums.size 阅读全文
posted @ 2020-04-16 10:14 Jinxiaobo0509 阅读(103) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 // 前i个字符串构成 == 前i-1个字符串构成(只有一个字符1-9) 5 // +前i-2个字符串构成(只有两个字符10-26) 6 int numDecodings(string s) 7 { 8 int n = s.size( 阅读全文
posted @ 2020-04-16 09:58 Jinxiaobo0509 阅读(181) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int uniquePathsWithObstacles(vector<vector<int>>& nums) 5 { 6 int m = nums.size(); 7 int n = nums[0].size(); 8 9 //起点 阅读全文
posted @ 2020-03-19 20:31 Jinxiaobo0509 阅读(95) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int lengthOfLIS(vector<int>& nums) 5 { 6 if(nums.size() == 0) return 0; 7 int n = nums.size(); 8 int res = INT_MIN; 9 阅读全文
posted @ 2020-03-19 12:56 Jinxiaobo0509 阅读(103) 评论(0) 推荐(0)
摘要:1 //看成一个下三角形 2 class Solution 3 { 4 public: 5 int minimumTotal(vector<vector<int>>& triangle) 6 { 7 int n = triangle.size(); 8 int res = INT_MAX; 9 ve 阅读全文
posted @ 2020-03-19 11:39 Jinxiaobo0509 阅读(165) 评论(0) 推荐(0)
摘要:1 class Solution 2 { 3 public: 4 int maxSubArray(vector<int>& nums) 5 { 6 int n = nums.size(); 7 vector<int> dp(n + 5,0); 8 dp[0] = nums[0]; 9 int res 阅读全文
posted @ 2020-03-18 23:02 Jinxiaobo0509 阅读(92) 评论(0) 推荐(0)