动态规划
文章平均质量分 86
forest小拳拳
这个作者很懒,什么都没留下…
展开
-
动态规划—钢条切割问题
动态规划里的钢条切割问题长度i与价格pi的对应表为:长度i :1,2,3,4,5 ,6 ,7 ,8 ,9 ,10价格pi:1,5,8,9,10,17,17,20,24,30现在考虑给出一个长度为n英寸的钢条,通过动态规划找出最优的切割方案,以此达到最佳收益:这里有两种方式能够解决该问题,一种是自顶向下带备忘的递归算法,一种是自底向上法(非递归),这里给出后者的算法(原创 2017-05-01 13:45:53 · 434 阅读 · 0 评论 -
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...原创 2019-01-28 13:23:18 · 110 阅读 · 0 评论 -
Leetcode-Unique Binary Search Trees
Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2 1 \ / ...原创 2018-03-13 20:40:35 · 112 阅读 · 0 评论 -
Leetcode-Climbing Stairs(dp)
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原创 2017-10-06 13:01:35 · 200 阅读 · 0 评论 -
Leetcode-Minimum Path Sum(dp)
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原创 2017-10-02 13:40:56 · 157 阅读 · 0 评论 -
Leetcode-Unique Paths(dp)
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the原创 2017-09-27 22:43:30 · 162 阅读 · 0 评论 -
Leetcode-Unique Paths II(dp)
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the原创 2017-09-28 17:04:15 · 204 阅读 · 0 评论 -
Leetcode-Edit Distance(dp)
Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:原创 2017-10-08 22:24:14 · 154 阅读 · 0 评论 -
贪心算法—活动选择问题
问题描述:假定有一个n个活动的集合S={a1,a2,......an},这些活动使用同一个资源(如一个阶梯教室),而这个资源在某个时刻只能供一个活动使用。每个活动有一个开始时间si和结束时间fi,其中0给出一个样例集合S:i 1 2 3 4 5 6 7 8 9 10 11si 1 3 0 5原创 2017-05-02 20:49:52 · 1171 阅读 · 0 评论 -
Leetcode-115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of S which equals T.A subsequence of a string is a new string which is formed from the original string by deleting some (ca...原创 2019-01-23 04:30:09 · 145 阅读 · 0 评论