DP

来源:互联网 发布:微信收费群设置 知乎 编辑:程序博客网 时间:2024/04/25 20:27
  1. Search "dynamic programming" in geekforgeeks.org
    1. Optimal Substructure: basically the formula that final answer can be derived from sub-problem answer
      1. Trying to solve the problem recursively may help you find the clue
    2. Overlapping Sub-problem: repeated computation of sub-problem
    3. Top-down may save time compared to bottom-up as it only calculates what's needed
    4. Interesting collection:
      1. http://www.careercup.com/question?id=5690555409367040
        1. Unresolved and not sure that's DP or not
      2. http://www.geeksforgeeks.org/dynamic-programming-set-37-boolean-parenthesization-problem/
        1. Sometimes you have to use 2+ extra supplementary data structures to achieve the goal
      3. http://www.geeksforgeeks.org/length-of-the-longest-arithmatic-progression-in-a-sorted-array/
        1. Very SMART idea: everytime just focus on finding triplet elements and use DP table to record the length and max length. PC has to exhaustively search for elements and find the best solution.
        2. Original paper from UIUC professor: http://web.engr.illinois.edu/~jeffe/pubs/pdf/arith.pdf
        3. Same idea can be used for arithmetic progression, geometric progression
      4. http://www.geeksforgeeks.org/dynamic-programming-set-31-optimal-strategy-for-a-game/
        1. Coin picking game mentioned a lot
      5. http://en.wikipedia.org/wiki/Longest_common_substring_problem
        1. Find suffix in all pairs of prefixes
        2. Extension: find out longest common string in multiple input strings
      6. http://www.geeksforgeeks.org/dynamic-programming-set-28-minimum-insertions-to-form-a-palindrome/
        1. What's the difference to just count how many missing chars to make up a palindrome?
      7. http://www.geeksforgeeks.org/largest-independent-set-problem/
        1. Typical BT strategy, though strictly speaking just memorization not DP and new additional field has to be added
      8. http://www.geeksforgeeks.org/dynamic-programming-set-24-optimal-binary-search-tree/
        1. The sum of all frequencies, the 1st term of the formula, is more like that each sub-tree root will be one level down in the sub-problem calculation while the sub-problem calculation does not factor in depth info. So it's easy to sum all frequencies together at one place.
      9. http://www.geeksforgeeks.org/dynamic-programming-set-18-word-wrap/
        1. Textbook typical DP problem that deals with how one extra word in a new line shuffle all previous lines!
        2. Please note a supplementary data structure is required to make it work efficiently, which is sometimes not that obvious. However it's not very hard to find out such requirement of supplementary data structure once you have nailed down DP formula. When working on DP[i], most of time need to look at not just DP[i-1], but also DP[i-2], ..., DP[i-k]
        3. Another possible approach is to average out the length of each line, in a hope that (a+b+c) cube is larger than a cube+b cube+c cube. DP does not require us to provide such proof and can do all the heavy lifting work for us
      10. http://www.geeksforgeeks.org/dynamic-programming-set-18-partition-problem/
        1. http://en.wikipedia.org/wiki/Partition_problem
        2. NP problem with pseudo-polynomial time
          1. http://www.geeksforgeeks.org/dynamic-programming-subset-sum-problem/
      11. http://www.geeksforgeeks.org/dynamic-programming-set-14-maximum-sum-increasing-subsequence/
        1. Variant of LIS, though we are looking for max sum instead of max length
        2. Another variant of LIS, http://www.geeksforgeeks.org/dynamic-programming-set-15-longest-bitonic-subsequence/
      12. http://www.geeksforgeeks.org/dynamic-programming-set-12-longest-palindromic-subsequence/
        1. Longest palindromic subsequence vs longest palindromic string
      13. http://www.geeksforgeeks.org/dynamic-programming-set-11-egg-dropping-puzzle/
        1. Very good DP solution, try get all intermediate floors
        2. Basically problem reduction in either dimension
      14. http://www.geeksforgeeks.org/dynamic-programming-set-7-coin-change/
        1. Please note this is a different but related version of counting how many different ways to climb stairs to reach top :)
        2. The idea is somehow similar to 0-1 backpack problem, http://www.geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/
  2. Longest increasing sequence (LIS)
    1. There is always a DAG of computation underlying every dynamic program but it is not always clear
    2. http://www.geeksforgeeks.org/dynamic-programming-set-3-longest-increasing-subsequence/
      1. http://www.gohired.in/2014/12/longest-increasing-subsequence.html (better illustration)
      2. Please note the time complexity is square. The wikipedia version has nlogn time complexity
    3. http://bix.ucsd.edu/bioalgorithms/book/excerpt-ch6.pdf
    4. http://wordaligned.org/articles/patience-sort.html (not sure correctness)
    5. Variant: http://www.geeksforgeeks.org/dynamic-programming-set-21-box-stacking-problem/
  3. Given n houses and m colors. The cost of painting different house with different color might be different. Find out the min cost of painting all houses such that no adjacent houses have same color.
  4. How to cut a log with min cost. For example a log of 10 meters with pre-set cuts on 2, 4 and 7 meters. Min cost is 20.
  5. Nine backpacks
    1. (56. pack2alpha1)
  6. There is typical way to cut down space complexity for DP, http://n00tc0d3r.blogspot.com/2013/04/minimum-path-sum.html
  7. Palindrome partitioning
    1. Sometimes you need to use DP twice, first build up the table, then use DP again to leverage the table, to find the final optimal solution.
    2. Her way to calculate min cuts is better as 1-dimensional array, instead of 2-dimensional table, is used. With 1-dimension we can always force either starting from first element or ending at the last element. If we use 2-dimension then calculate each single pair [i, j] alone is quadruple. More dimensions do not lead to better solution.
      1. Her approach is similar to this one mentioned here, http://www.geeksforgeeks.org/dynamic-programming-set-17-palindrome-partitioning/
    3. http://n00tc0d3r.blogspot.com/2013/05/palindrome-partitioning.html
    4. http://n00tc0d3r.blogspot.com/2013/05/palindrome-partitioning-ii.html
    5. http://n00tc0d3r.blogspot.com/2013/02/the-number-of-ways-to-decode-message.html
      1. Another example of memory optimization
  8. Word segmentation
    1. http://n00tc0d3r.blogspot.com/2013/03/word-segment.html
    2. Good example of bad (slower) and good (faster) DP
  9. http://forum.quant365.com/viewforum.php?f=3
    1. Seems lots of hot companies interview questions
  10. Suppose we are given a set L of n line segments in the plane, where the endpoints of each segment lie on the unit circle x^2 + y^2 = 1, and all 2n endpoints are distinct. Describe and analyze an algorithm to compute the largest subset of L in which no pair of segments intersects
    1. (58. facebook interview (good problem reduction then DP))
  11. RESERVED
0 0
原创粉丝点击