![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
i-Blue
抱平常心走平常路
展开
-
131. Palindrome Partitioning
回文分割。 DP+dfs。 先判断str中任意字串是否是回文,用动态规划方法: //construct the pailndrome checking matrix // 1) matrix[i][j] = true; if (i==j) -- only one char // 2) matrix[i][j] = true; if (i==j+1) && s[i]==s[j] -- o原创 2016-08-16 00:49:37 · 393 阅读 · 0 评论 -
最长递增子序列
问题 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱)。例如:给定一个长度为6的数组A{5, 6, 7, 1, 2, 8},则其最长的单调递增子序列为{5,6,7,8},长度为4. 解法1:最长公共子序列法 这个问题可以转换为最长公共子序列问题。如例子中的数组A{5,6, 7, 1, 2, 8},则我们排序该数组得到数组A‘{1, 2, 5, 6转载 2017-03-31 23:28:00 · 389 阅读 · 0 评论 -
416. Partition Equal Subset Sum子数组和问题
相同子集和分割。 与0-1背包相似:01背包(1)、01背包(2)。 问题: Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets转载 2017-02-13 22:10:30 · 1197 阅读 · 2 评论 -
LeetCode Maximum Product Subarray_DP_最大子数组
题目:Maximum Product Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest product. For example, given the array [2,3,-2,4], the contig原创 2017-01-07 16:07:17 · 343 阅读 · 0 评论 -
最大子序列和问题的解_
问题:有数n1,n2,......,ns。求一个连续的子序列,这个序列的和最大。 这个问题有O(n^3)、O(n^2)、O(n*lgn)以及O(n)时间复杂度的解法。 下面主要说下O(n*lgn)和O(n)的解法。原创 2016-12-14 19:47:43 · 486 阅读 · 0 评论 -
377. Combination Sum IV-动态规划
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target. Example: nums = [1, 2, 3] target = 4 The pos原创 2016-09-22 19:54:56 · 1287 阅读 · 0 评论 -
53. Maximum Subarray-动态规划/分治
题: Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1原创 2016-09-04 17:30:45 · 943 阅读 · 0 评论 -
Russian Doll Envelopes-最长递增子序列
方法:DP+ 二分搜索 具体一点说,二分搜索是用在LIS(最长递增子序列)中(LIS见:点击打开链接)。主要思想就是LIS的思想。 有O(N*N)和O(NlgN)两种解法。 不论是哪种解法,首先都得按照w(宽)值对envelopes进行递增排序。 简单直观的O(N*N)的方法。 class Solution { public: int maxEnvelopes(vector>& env原创 2016-08-17 01:12:34 · 319 阅读 · 0 评论 -
198. House Robber-动态规划
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house原创 2016-09-13 15:29:05 · 649 阅读 · 0 评论 -
174. Dungeon Game-动态规划
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially p原创 2016-09-12 21:43:43 · 375 阅读 · 0 评论 -
10. Regular Expression Matching-动态规划/递归回溯
mplement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the entire input str原创 2016-09-11 21:40:08 · 1111 阅读 · 0 评论 -
307. Range Sum Query - Mutable
Tags--binary indexed tree(二分索引树,树状数组)原创 2016-08-19 20:31:39 · 448 阅读 · 0 评论 -
binary indexed tree 二分索引树 树状数组
参考: https://www.byvoid.com/blog/binary-index-tree http://www.cnblogs.com/sixdaycoder/p/4348360.html http://blog.csdn.net/liangzhaoyang1/article/details/51365192 1)求Ci C[i] = A[i-2^k+1]原创 2016-08-19 20:07:34 · 1446 阅读 · 0 评论 -
[LeetCode] Unique Paths-动态规划
开一个f[m][n]的数组,f[i][j] = f[i-1][j] + f[i][j-1],空间时间复杂度O(m*n)。用滚动数组空间复杂度可降为O(n)原创 2016-07-21 21:00:30 · 284 阅读 · 0 评论 -
494. Target Sum-回溯法、DP。
可以使用方法:回溯法、DP。 相近的问题:Partition Equal Subset Sum、01背包(1)、01背包(2)。 问题描述: You are given a list of non-negative integers, a1, a2, ..., an, and a target, S. Now you have 2 symbols + and -. For ea原创 2017-02-13 22:30:49 · 1956 阅读 · 0 评论