动态规划 (DP)
文章平均质量分 74
beiyetengqing
http://blog.youkuaiyun.com/beiyeqingteng 的镜像站
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
01背包问题
问题: 有 N 件物品和一个容量为 M 的背包。第 i 件物品的体积是w[i],价值是p[i]。求解将哪些物品装入背包可使这些物品的体积总和不超过背包容量,且价值总和最大。 分析: 这个问题的难点在于它有很多种组合情况,所以,这个问题看似很难在 polynomial 时间内找出最优解。但是,我们的确可以在polynomial时间内找出来。 思路如下: 对于问题本身,背包的容量是物品的原创 2012-10-09 08:55:17 · 818 阅读 · 0 评论 -
Java实现最长公共子序列
最长公共子序列(LCS)定义: 一个数列 S,如果分别是两个或多个已知数列的子序列,且是所有符合此条件序列中最长的,则 S 称为已知序列的最长公共子序列。比如数列A = “abcdef”, B = “adefcb”. 那么两个数列的公共子序列是"adef". 最长公共子序列和最长公共子字符串是有区别的,公共子序列里的元素可以不相邻,但是公共子字符串必须是连接在一起的。比如A和B的公共子字符串原创 2012-12-03 11:48:21 · 1287 阅读 · 0 评论 -
括号匹配
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. The brackets must close in the correct order, "()" and "()[]{}" are all va原创 2012-06-27 12:27:44 · 676 阅读 · 0 评论 -
Climbing Stairs
Question: 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? public class So原创 2012-12-10 00:44:57 · 3327 阅读 · 0 评论 -
Unique Paths II
Question: 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 respect原创 2012-12-10 03:55:09 · 1830 阅读 · 0 评论 -
编辑距离 (edit distance)
问题: 给定两个字符串 A和B,由A转成B所需的最少编辑操作次数。允许的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。 例如将A(kitten)转成B(sitting): sitten (k→s)替换 sittin (e→i)替换 sitting (→g)插入 思路: 如果我们用 i 表示当前字符串 A 的下标,j 表示当前字符串 B 的下标。 如果我们用d原创 2012-10-24 02:59:34 · 13736 阅读 · 0 评论 -
添加最少括号使得给定括号字符串匹配
问题: 给你一个字符串,里面只包含"(",")","[","]"四种符号,请问你需要至少添加多少个括号才能使这些括号匹配起来。 如: []是匹配的,所需括号个数为 0. ([])[]是匹配的, 所需括号个数为 0. ((]是不匹配的, 所需最少括号个数为 3. ([)]是不匹配的,所需最少括号个数为 2. 分析: 此题来自:http://blog.csd原创 2012-09-29 11:46:09 · 1809 阅读 · 0 评论
分享