For example we have 'a' -> 1 'b' -> 2 .. 'z' -> 26 By given "12", we can decode the string to give result "ab" or 'L', 2 ways to decode, your function should return 2 as an answer. Now asking by given "1246", what sh…
For example there is a staricase N = 3 | ---|   |---|    | |---|            | ---|                  | There is N = 3 staricase, for each step, you can either take {1 or 2} step at a time. So asking how many ways you can get on N = 3 step: Answer: sho…
1. Longest Increasing Subsequence (LIS) problem unsorted array, calculate out the maximum length of subsequence with non-decreasing order. lis[i] = lis[j] + 1 if arr[i] > arr[j]; lis[i] is the lis with arr[i] as the last element. so to get the maximu…
For a given array, we try to find set of pair which sums up as the given target number. For example, we are given the array and target as: , , , ]; ; We should be able to find 2 pair, which sum up to 16: {,,} {,} We need to create a function to retur…
https://leetcode.com/problems/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 the total number of wa…
动态规划(Dynamic Programming)是求解决策过程(decision process)最优化的数学方法.它的名字和动态没有关系,是Richard Bellman为了唬人而取的. 动态规划主要用于解决包含重叠子问题的最优化问题,其基本策略是将原问题分解为相似的子问题,通过求解并保存重复子问题的解,然后逐步合并成为原问题的解.动态规划的关键是用记忆法储存重复问题的答案,避免重复求解,以空间换取时间. 用动态规划解决的经典问题有:最短路径(shortest path),0-1背包问题(K…
作者:Dumitru 出处:http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProg An important part of given problems can be solved with the help of dynamic programming (DP for short). Being able to tackle problems of this type would greatly in…
“就是迭代,被众人说得这么玄乎" “之所以归为优化,是因为动态规划本质是一个systemetic bruce force" “因为systemetic,所以比穷举好了许多,就认为是优化的功绩咯" 不等长活动的安排 活动不等长,安排利用率最高的活动安排. T(n) 不一定是最大,所以,最后要找出Table中的T(1)->T(n)中最大的,即是最优的. 最长递增子序列 给定一个长度为N的数组,找出一个最长的单调自增子序列(不一定连续,但是顺序不能乱). 例如:给定一个长度为…
Main Point: Dynamic Programming = Divide + Remember + Guess 1. Divide the key is to find the subproblem 2. Remember use a data structure to write down what has been done 3. Guess when don't know what to do, just guess what next step can be Problems:…
We began our study of algorithmic techniques with greedy algorithms, which in some sense form the most natural approach to algorithm design. Faced with a new computational problem, we've seen that it's not hard to propose multiple possible greedy alg…