随笔分类 -  Dynamic Programming

摘要:描述 描述 给出两个单词word1和word2,计算出将word1 转换为word2的最少操作次数。 你总共三种操作方法: 插入一个字符 删除一个字符 替换一个字符 动态规划问题, 当进行一步操作后,将A[2...lenA] B[2...lenB]变成相等字符串 当进行一步操作后,将A[1...le 阅读全文
posted @ 2018-07-25 11:15 immjc 阅读(210) 评论(0) 推荐(0)
摘要:给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 给出三个字符串:s1、s2、s3,判断s3是否由s1和s2交叉构成。 样例 比如 s1 = 阅读全文
posted @ 2018-07-24 17:43 immjc 阅读(306) 评论(0) 推荐(0)
摘要:题目描述 给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数。当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案。 输入描述: 输入为两行: 第一行为两个正整数n(1 ≤ n ≤ 1000),sum(1 ≤ sum ≤ 1000) 第二行为n个正整数 阅读全文
posted @ 2017-08-31 18:31 immjc 阅读(257) 评论(0) 推荐(0)
摘要:给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度。 给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度。 给出两个字符串,找到最长公共子序列(LCS),返回LCS的长度。 说明 最长公共子序列的定义: 最长公共子序列问题是在一组序列(通常2个)中找到最长公共子序列(注意:不 阅读全文
posted @ 2017-08-26 13:48 immjc 阅读(171) 评论(0) 推荐(0)
摘要:给出一个都是正整数的数组 nums,其中没有重复的数。从中找出所有的和为 target 的组合个数。 注意事项 一个数可以在组合中出现多次。数的顺序不同则会被认为是不同的组合。 您在真实的面试中是否遇到过这个题? Yes 给出一个都是正整数的数组 nums,其中没有重复的数。从中找出所有的和为 ta 阅读全文
posted @ 2017-08-25 21:21 immjc 阅读(150) 评论(0) 推荐(0)
摘要:给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大? 注意事项 A[i], V[i], n, m均为整数。你不能将物品进行切分。你所挑选的物品总体积需要小于等于给定的m。 您在真实的面试中是否遇到过这个题? Yes 给出n个物品的体积A[i]和其价值V 阅读全文
posted @ 2017-08-25 20:27 immjc 阅读(143) 评论(0) 推荐(0)
摘要:在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i] 注意事项 你不可以将物品进行切割。 在n个物品中挑选若干物品装入背包,最多能装多满?假设背包的大小为m,每个物品的大小为A[i] 注意事项 你不可以将物品进行切割。 在n个物品中挑选若干物品装入背包,最多能 阅读全文
posted @ 2017-08-25 16:40 immjc 阅读(142) 评论(0) 推荐(0)
摘要:You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you nee 阅读全文
posted @ 2017-08-25 13:26 immjc 阅读(132) 评论(0) 推荐(0)
摘要: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 yo 阅读全文
posted @ 2017-08-23 17:13 immjc 阅读(125) 评论(0) 推荐(0)
摘要: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, 阅读全文
posted @ 2017-07-25 18:16 immjc 阅读(118) 评论(0) 推荐(0)
摘要: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 cl 阅读全文
posted @ 2017-07-23 18:34 immjc 阅读(141) 评论(0) 推荐(0)
摘要:Say you have an array for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction 阅读全文
posted @ 2017-07-19 18:34 immjc 阅读(130) 评论(0) 推荐(0)