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. AOP reading notes

    2022-10-10

  2. Shiro基本使用

    2020-10-31

  3. Setting Up and Maintaining a Ubuntu Environment for My Home Server

    2023-11-24

  4. Java 容器

    2020-08-03

There are no comment yet.

COMMENT

Take a Coffee Break

Recommend post

  1. 常用工具指令

    2022-09-18

Category list

ABOUT

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

June 2025
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  

Life Logs

  1. 回首

    2023-07-14

Return Top