动态规划
文章平均质量分 73
liuchenjane
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Frog Jump
A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a list of ston转载 2016-10-09 21:46:23 · 1458 阅读 · 0 评论 -
474. Ones and Zeroes
474. Ones and ZeroesIn the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s andn 1s re转载 2016-12-16 09:22:16 · 1025 阅读 · 0 评论 -
322. Coin Change
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 need to make up that amount. If that amount of money转载 2017-01-02 15:46:15 · 296 阅读 · 0 评论 -
10. Regular Expression Matching
Implement 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 st转载 2017-01-13 17:15:17 · 248 阅读 · 0 评论 -
32. Longest Valid Parentheses
iven a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", w转载 2017-01-15 20:16:02 · 363 阅读 · 0 评论 -
动态规划预测游戏输赢的问题总结
在leetcode中,经常会遇到判断两人游戏,一方是输还是赢的问题。有guess number higher or lower, can I win,predict the winner等。这类问题都假设双方在最优策略下,甲方是否会赢。 这类问题都可以用动态规划来解决,关键在于采用top-down的备忘录策略,每解决一个小的子问题,都把相应的结果记录在备忘录上,下次遇到相同的问题时,直接查询即可原创 2017-02-09 11:09:31 · 2191 阅读 · 0 评论 -
115. Distinct Subsequences
Given a string S and a string T, count the number of distinct subsequences of T in S.A subsequence of a string is a new string which is formed from the original string by deleting some (can be non转载 2017-02-27 22:23:59 · 412 阅读 · 0 评论 -
44. Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover t原创 2017-02-10 16:02:12 · 374 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing only 1's and return its area.For example, given the following matrix:1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0原创 2017-03-01 21:59:59 · 279 阅读 · 0 评论 -
304. Range Sum Query 2D - Immutable
Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).The above rectangle (with the red bo原创 2017-02-25 16:15:54 · 409 阅读 · 0 评论 -
97. Interleaving String
Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example, Given: s1 = “aabcc”, s2 = “dbbca”,When s3 = “aadbbcbcac”, return true. When s3 = “aadbbbaccc”, return false原创 2017-02-25 21:51:39 · 323 阅读 · 0 评论 -
360笔试遇到的博弈问题(DP)
昨天,第一次参加找工作的笔试,最后一道编程题,总觉得很熟悉,但是没有做出来。以后,有时间记录下遇到的问题,便于以后看看。 题目是360公司的,大概讲的是两队海盗分金子,每次只能从一端取(左或者右),假设每队都按照最优的策略,问最后各取多少金子。 以前在LeetCode里也碰到过类似做游戏的问题,464. can I win,486. Predict the Winner。事后,发现这个题目和48原创 2017-03-19 10:27:03 · 1241 阅读 · 0 评论 -
最优二叉搜索树
问题描述: 给定一个n个不同关键字的已排序的序列K=<k1,k2,...,kn>K=<k_1,k_2,...,k_n>,每个关键字都有一个概率pip_i表示其搜索频率,希望构造一颗搜索代价最小的二叉搜索树。 用于实例的二叉树: 对于一个n=5n=5的关键字集合及如下搜索概率,构造二叉树。 ii 0 1 2 3 4 5 pip_i 0.15 0.1原创 2016-11-24 20:03:22 · 1031 阅读 · 0 评论 -
矩阵链乘问题
问题描述: 给定n个矩阵的链<A1,A2,...,An><A_1,A_2,...,A_n>,矩阵AiA_i的规模为pi×pi+1(1≤i≤n)p_i \times p_{i+1}(1\le i \le n),求完全括号化的方案,使得计算乘积A1,A2,...,AnA_1,A_2,...,A_n所需标量乘法的次数最少。 递推式: m[i,j]={0,min{m[i,k]+m[k+1,j]+pi原创 2016-11-24 19:21:01 · 499 阅读 · 0 评论 -
467. Unique Substrings in Wraparound String
467. Unique Substrings in Wraparound StringConsider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz", so s will look like this: "...zabcdefghijklmnopqrstuvwxyz转载 2016-12-06 21:24:47 · 488 阅读 · 0 评论 -
动态规划解决最长公共子序列LCS问题
子序列的定义:给定一个序列X=,另一个序列Z=,满足如下条件时称为X的子序列,即存在一个严格递增的X的下标序列和所有的j=1,2,...,k,满足Zj=X[ik]下标序列,使得它们都相等。如是X=的子序列。给定两个序列X和Y,如果Z既是X的子序列,也是Y的子序列,我们称它是X和Y的公共子序列。LCS问题:给定两个序列,求X和Y长度最长的公共子序列。分析:LCS具有最优子结构性质原创 2016-09-22 09:53:08 · 3412 阅读 · 0 评论 -
Edit Distance
Edit DistanceGiven 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 p转载 2016-09-21 21:58:43 · 317 阅读 · 0 评论 -
动态规划解决0_1背包问题
动态规划解决0/1背包问题:这里的测试例子如下:假设物品已经按照单位重量价值由大到小排好序了。const int Max=8;const int weight[Max]={1,11,21,23,33,43,45,55};const int value[Max]={11,21,31,33,43,53,55,65};int W=110;分析:这里定义一个二维数组vector原创 2016-09-20 19:19:31 · 613 阅读 · 0 评论 -
396. Rotate Function
396. Rotate Function QuestionEditorial Solution My SubmissionsTotal Accepted: 1777Total Submissions: 6445Difficulty: EasyGiven an array of integers A and let n原创 2016-09-13 15:09:06 · 580 阅读 · 0 评论 -
300. Longest Increasing Subsequence
300. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.For example,Given [10, 9, 2, 5, 3, 7, 101, 18],The longest incre原创 2016-10-22 21:53:50 · 406 阅读 · 0 评论 -
钢条切割问题
//dp解决钢条切割问题//问题:给定一个长度为n英寸的钢条和一个价目表p[i](i=1,2,...,n),求切割钢条方案,使得销售收益最大//递推:r[n]=max{p[n],r[1]+r[n-1],r[2]+r[n-2],...,r[n-1]+r[1]}; #include #include #include int n=10; int p[10]={1,5,8,9,10,17,原创 2016-11-05 18:03:29 · 585 阅读 · 0 评论 -
198. House Robber
198. House RobberYou 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转载 2016-10-26 17:26:03 · 288 阅读 · 0 评论 -
213. House Robber II
213. House Robber IINote: This is an extension of House Robber.After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too转载 2016-10-26 22:15:06 · 311 阅读 · 0 评论 -
139. Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, given s = “leetcode”, dict = [“leet”, “co转载 2016-10-20 21:02:10 · 368 阅读 · 0 评论 -
279. Perfect Squares
279. Perfect SquaresGiven a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.For example, given n = 12, return 3 because 1转载 2016-11-14 21:35:09 · 495 阅读 · 0 评论 -
152. Maximum Product Subarray
152. Maximum Product SubarrayFind 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 contigu转载 2016-11-15 15:43:29 · 324 阅读 · 0 评论 -
Longest Line of Consecutive One in Matrix
Given a 01 matrix M, find the longest line of consecutive one in the matrix. The line could be horizontal, vertical, diagonal or anti-diagonal.Example: Input: [[0,1,1,0], [0,1,1,0], [0,0,0,1]] O翻译 2017-04-23 21:12:44 · 975 阅读 · 0 评论
分享