
dynamic programming
文章平均质量分 71
yuanhisn
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
k-palindrome
Question: A k-palindrome is a string which transforms into a palindrome on removing at most k characters. Given a string S, and an interger K, print “YES” if S is a k-palindrome; otherwise print “...原创 2015-03-09 10:45:25 · 173 阅读 · 0 评论 -
Longest Increasing Subsequence
一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度。 (讲DP基本都会讲到的一个问题LIS:Longest Increasing Subsequence) 面对这样一个问题,我们首先要定义一个“状态”来代表它的子问题, 并且找到它的解。注意,大部分情况下,某个状态只与它前面出现的状态有关, 而独立于后面的状态。 我们来找一下“状态”和“状态转移方程”。 假如我们考...原创 2015-03-12 05:14:26 · 73 阅读 · 0 评论 -
A crack at Dynamic Programming
From: http://blog.rfaisal.com/2013/05/19/a-crack-at-dynamic-programming/ Dynamic Programming is a discrete optimization technique. It means, the variables we want to calculate using this method are...原创 2015-03-19 06:57:07 · 116 阅读 · 0 评论 -
Google Interview - 数字旋转180度
找出1~10^n中数字翻转过来是本身的数( 96 ->96, 18 -> 81, 0 -> 0, 其他数字翻过来都不是数字) 设计一个函数,判断某个只包含数字的字符串是不是Ambigram(比如,69,88,609,818等都是Ambigram)。Follow up:给一个整数n,找出所有长为n的Ambigram。 可以先求出n-2的答案,再利用n-2的答案求出n的答案,...原创 2015-03-20 05:46:35 · 122 阅读 · 0 评论 -
Egg Dropping Puzzle
Question: There is a building of 100 floors If an egg drops from the Nth floor or above it will break. If it’s dropped from any floor below, it will not break. You’re given 2 eggs. Find N, while m...原创 2015-03-26 02:56:45 · 128 阅读 · 0 评论 -
LeetCode 213 - House Robber II
Note: 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 much attention. This time,...原创 2015-05-26 14:12:32 · 84 阅读 · 0 评论 -
Google Interview - Fence Painter
Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors such that no more than 2 adjacent fence posts are painted with the same color. 因为题目要求是不超过两个相邻...原创 2015-06-16 12:55:43 · 95 阅读 · 0 评论 -
Longest Palindrome Subsequence
Given a sequence, find the length of the longest palindromic subsequence in it. For example, if the given sequence is “BBABCBCAB”, then the output should be 7 as “BABCBAB” is the longest palindromic ...原创 2015-06-23 14:07:31 · 128 阅读 · 0 评论 -
Hedvig Interview - Count of number with no consecutive 1's
Given integer n, find the number of different binary strings of size n where there are no consecutive 1's.Eg: If n is 2, valid strings are 00, 01, 10. You should return 3. 假设f(n, k)是第n位上为k的数字的个数无...原创 2015-07-22 14:14:01 · 100 阅读 · 0 评论 -
石子合并问题
[问题描述]: 设有n堆石子排成一排,其编号为1、2、3、…、n(n<=100)。每堆石子的数量用:a[1]、a[2]、…、a[n] 表示,现将这n堆石子归并成一堆,归并的规则: ◆每次只能将相邻两堆归并成一堆,即:第 1 堆石子 a[1] 只能与第 2 堆石子 a[2] 归并,最后一堆石子 a[n] 只能与 a[n-1] 归并,中间的石子 a[i] 只能与 a[i-1] 或 a[i...原创 2015-07-29 22:58:44 · 343 阅读 · 0 评论 -
LeetCode 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 inp...原创 2015-03-02 08:13:27 · 89 阅读 · 0 评论 -
[待续]Convert string to palindrome string with minimum insertions
Given a string, find the minimum number of characters to be inserted to convert it to palindrome. For Eg :- ab: Number of insertions required is 1. bab aa: N...原创 2015-02-26 05:47:17 · 224 阅读 · 0 评论 -
LeetCode - Best Time to Buy and Sell Stock III
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions. Note:You may not ...原创 2015-01-14 03:08:45 · 176 阅读 · 0 评论 -
LeetCode - Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 Given an encoded message containing digits, determine t...原创 2015-01-18 17:20:34 · 97 阅读 · 0 评论 -
LeetCode - 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...原创 2015-01-19 12:22:46 · 86 阅读 · 0 评论 -
LeetCode - 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....原创 2015-01-20 00:38:44 · 82 阅读 · 0 评论 -
LeetCode - Dungeon Game
The demons had captured the princess (P) 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 p...原创 2015-01-21 15:26:40 · 100 阅读 · 0 评论 -
Number of unique ways that ATM can tender
An atm can only dispense values of $1, $5, $20, and $50. Return the number of unique ways that a $ amount of X can be tendered.($1, $5) is distinct from ($5, $1)Input: 4 Output: 1Input: 6 Output: 3I...原创 2015-01-22 03:28:29 · 92 阅读 · 0 评论