
动态规划
weixin_42741175
这个作者很懒,什么都没留下…
展开
-
动态规划问题
目录动态规划的递归写法和递推写法典型例题总结1.动态规划的递归写法和递推写法1.1 动态规划的递归算法以斐波那契数列为例,用一般的递归写法写出如下代码:int F(int n){ if(n==0||n==1) return 1; else return F(n-1)+F(n-2);}但上面代码会产生许多的重复计算,为了避免重复计算,可以新开一个一维数组dp,用来保存已经...原创 2019-06-17 16:09:31 · 373 阅读 · 0 评论 -
leetcode 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest increasing subsequence is [2,3,7,101], ...原创 2019-05-14 22:20:59 · 91 阅读 · 0 评论 -
leetcode 72. Edit Distance 编辑距离(字符串动态规划)
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a characterDelete a characte...原创 2019-05-12 22:27:57 · 241 阅读 · 0 评论 -
leetcode 96. Unique Binary Search Trees (好题)
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total of 5 unique BST’s:1 3 3 ...原创 2019-05-11 16:56:24 · 109 阅读 · 0 评论 -
leetcode 174. Dungeon Game (动态规划经典题)
The demons had captured the princess § 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 posit...原创 2019-05-09 21:32:20 · 159 阅读 · 0 评论 -
leetcode 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at an...原创 2019-05-09 20:24:40 · 107 阅读 · 0 评论 -
leetcode 120.triangle(动态规划经典题)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[[2],[3,4],[6,5,7],[4,1,8,3]...原创 2019-05-08 16:52:05 · 197 阅读 · 0 评论 -
leetcode 53. Maximum Subarray(动态规划经典题)
Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Explanation:...原创 2019-05-08 15:33:09 · 168 阅读 · 0 评论 -
Leetcode 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...原创 2019-05-08 15:01:13 · 174 阅读 · 0 评论 -
LeetCode 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?Note: Given n will be a positive i...原创 2019-05-07 23:56:33 · 102 阅读 · 0 评论