DP问题专项

一. General Idea

DP ≈ recursion + memorization + guessing
memorize(remember) & reuse solutions to subproblems that help solve the problem.
time = #subproblems * time/subproblem, treating recursive call as Θ(1).

Bottom-up DP algorithm: topological sort of subproblem dependency DAG
often can save space

Guessing: try all guesses and take the best one

Shortest paths:
guess: 既然不知道哪条路到最后的节点最短那就全试一遍,然后选最短的路(无法解决环路问题)

为解决环路问题,引入了k

二. 5 “easy” steps to DP:

  1. define subproblems
    #subproblems
  2. guess
    #choices for guess
  3. relate subproblem solutions
    time/subproblem (similar to #choices for guess)
  4. recurse & memorize or build DP table bottom-up
    check subproblem recurrence is acyclic, i.e. has topological order
    total time
  5. solve original problem
    extra time

三. Subproblems for strings/sequences

  1. suffixes x[i:] ∀i
  2. prefixes x[:i] ∀i
  3. substrings x[i:j] ∀i≤j
    once find I need to use both 1 and 2, then mostly I need to use 3

四. Kinds of guessing

1 in 2(&3): guessing which subproblem to use to solve the bigger subproblem

2 in 1: add more subproblems to guess/remember more

Related post

  1. Keras Embedding层

    2020-07-21

  2. vi编译器查询手册

    2020-09-23

  3. Java 编码

    2020-07-31

  4. MapReduce代码编写总览

    2021-09-20

There are no comment yet.

COMMENT

Take a Coffee Break

Recommend post

  1. 常用工具指令

    2022-09-18

ABOUT

Welcome to FullStar, a captivating online destination where the realms of software development and personal reflections intertwine.

September 2025
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
2930  

Life Logs

  1. 回首

    2023-07-14

Return Top