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…
作者: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…
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…