动态规划
zhaohoutao
这个作者很懒,什么都没留下…
展开
-
LeetCode-91 解码方法
本人的解法: int numDecodings(string s) { //使用动态规划的方法: //缺陷是使用了十位与个位数字得到的结果进行比较 int len = s.size(); vector<int> dp(len + 1, 0); dp[0] = 1; for (int i = 0; i<len; ++i) { if (i == 0) { ...原创 2019-05-01 22:14:56 · 96 阅读 · 0 评论 -
LeetCode 343 整数拆分
整数拆分 class Solution { public: int integerBreak(int n) { //整数拆分的算法 vector<int> dp(n+1,INT_MIN); dp[1]=1; for(int i=2;i<=n;++i) { for(in...原创 2019-08-26 01:01:13 · 112 阅读 · 0 评论 -
LeetCode 410 分割数组的最大值
分割数组的最大值 class Solution { public: int splitArray(vector<int>& nums, int m) { //使用动态规划的算法 int len = nums.size(); int min_max_result = INT_MAX; vector<vector<long long>> d...原创 2019-08-25 21:57:40 · 109 阅读 · 0 评论 -
LeetCode 72 编辑距离
编辑距离 class Solution { public: int minDistance(string word1, string word2) { //编辑距离使用动态规划的算法进行 int len1 = word1.size(); int len2 = word2.size(); vector<vector<int>> dp(len1 + 1, vec...原创 2019-08-11 20:03:53 · 68 阅读 · 0 评论 -
LeetCode 买卖股票的动态规划通用方法
买卖股票的动态规划通用方法 参考:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock-iii/solution/yi-ge-tong-yong-fang-fa-tuan-mie-6-dao-gu-piao-wen/ 具体题目 class Solution { public: int maxProfit(vect...原创 2019-07-25 21:52:50 · 574 阅读 · 0 评论 -
LeetCode-140 单词拆分 II
单词拆分 II 跟别人的代码比起来可能会长一点儿 class Solution { public: bool isvalue(string s, string temp) { if (s == temp) return true; return false; } bool find_a(vector<string>& wordDict, string s) {...原创 2019-07-21 16:45:13 · 89 阅读 · 0 评论 -
LeetCode- 139 单词拆分
单词拆分 回溯算法会超时 class Solution { public: bool isvalue(string s, string temp) { if (s == temp) return true; return false; } void huisu(string s, vector<string>& wordDict,int& count)...原创 2019-07-21 16:43:11 · 98 阅读 · 0 评论 -
LeetCode-32 最长有效括号
最长有效括号 看了参考答案的提示写了一下,然后自己调试bug,发现这里对于一种情况不太行,标注 class Solution { public: int longestValidParentheses(string s) { //最长有效括号使用,包含有效括号怎么办使用动态规划 int len = s.size(); int begin = 0; int end = 0; int...原创 2019-07-29 17:10:10 · 81 阅读 · 0 评论 -
LeetCode-152 乘积最大子序列
乘积最大子序列 class Solution { public: int maxProduct(vector<int>& nums) { //使用动态规划的算法进行相应的计算过程 //使用跟求最大连续子序列和一样的算法,这里有负数所以和相加还有一点儿区别的 int len=nums.size(); int...原创 2019-07-19 20:51:08 · 88 阅读 · 0 评论 -
拼多多的笔试题目总结
拼多多笔试题目(没有参加只是自己看看) 第一题:思路大体能有 void panduan(vector<int> &A, vector<int> B) { //两次遍历的算法 int lenA = A.size(); int lenB = B.size(); int gaibian = 0; for (int i = 0; i < lenA; ++...原创 2019-07-29 13:48:39 · 1849 阅读 · 0 评论 -
LeetCode-221 最大正方形
最大正方形 class Solution { public: int maximalSquare(vector<vector<char>>& matrix) { //使用动态规划的算法进行详细的解答过程 //这种题型其实很常见的 int col = matrix.size(); if(col==0) return 0; in...原创 2019-07-12 16:26:59 · 92 阅读 · 0 评论 -
动态规划-背包问题
背包问题 1.不可以重复取每个物品 int beibao(vector<int> W, vector<int> V, int sum) { //使用动态规划的算法 int len = W.size(); vector<vector<int>> dp(len, vector<int>(sum+1,0)); //dp[i][j]表...原创 2019-07-18 16:02:17 · 95 阅读 · 0 评论 -
LeetCode-174 地下城游戏
地下城游戏 class Solution { public: int calculateMinimumHP(vector<vector<int>>& dungeon) { //这里需要向后递推过程的,从右下角转到左上角 vector<vector<int>> dp = dungeon; int col = dungeon.si...原创 2019-07-10 23:35:14 · 91 阅读 · 0 评论 -
LeetCode-322 找零钱
找零钱 class Solution { public: int coinChange(vector<int>& coins, int amount) { //使用动态规划算法,对于贪心算法必须保证这些是倍数增长的所以没有必要进行贪心策略 //必须使用动态规划算法进行相应的计算 int len= coins.size()...原创 2019-07-10 19:30:16 · 293 阅读 · 0 评论 -
LeetCode-213 打家劫舍2
打家劫舍2 class Solution { public: int rob(vector<int>& nums) { //使用动态规划 的算法 int len = nums.size(); if(len==0) return 0; if(len==1) return nums[0]; vector<int&...原创 2019-07-13 20:34:44 · 202 阅读 · 0 评论 -
LeetCode-120三角形最小路径和
class Solution { public: int minimumTotal(vector<vector<int>>& triangle) { //使用动态规划 int len=triangle.size(); //vector<int > dp(len); vector&l...原创 2019-05-02 01:04:02 · 90 阅读 · 0 评论 -
LeetCode 873 最长的斐波那契子序列的长度
最长的斐波那契子序列的长度 class Solution { public: int lenLongestFibSubseq(vector<int>& A) { //使用动态规划算法 int max_len=0; int len=A.size(); if(len<=2) re...原创 2019-08-29 22:49:34 · 247 阅读 · 0 评论