Fullstar

Archives

  • December 2025
  • August 2024
  • July 2024
  • February 2024
  • November 2023
  • August 2023
  • July 2023
  • January 2023
  • November 2022
  • October 2022
  • September 2022
  • February 2022
  • January 2022
  • September 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020

Categories

  • Code
  • Lens
  • Life
0
Fullstar
  • Code

DP问题专项

  • November 24, 2022
  • Brandon

Looking for a Shorter Overview?

AI Summary

Dynamic programming combines recursion, memorization, and informed guessing to reuse solutions for smaller subproblems. The article outlines a five-step DP design process, explains bottom-up ordering, and shows how extra state such as k can address cycles in shortest paths.

Key Moments

AI-generated
1

Dynamic programming core model

Treat dynamic programming as recursion with memorization and guessing, reusing subproblem solutions to avoid repeated work.
2

Bottom-up dependency order

Build a bottom-up DP table by processing the subproblem dependency DAG in topological order, which can also reduce space usage.
3

Five-step DP design process

Define subproblems, enumerate guesses, derive the recurrence, compute in an acyclic order with memorization or a table, and extract the original answer.
4

Sequence subproblem selection

Use suffixes, prefixes, or substrings as sequence subproblems, with substrings often needed when both prefix and suffix information matters.
Total
0
Shares
0
0
0

一. 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 Posts

AI-generated

Private: Leetcode解题日志

从双指针去重到动态规划定义子问题,再到单调栈、前缀和和图搜索,这份刷题日志沉淀了九百多道题中的易错点、优化方向与可复用模板。
50.7% match August 27, 2023

算法伪代码

从二分检索到八皇后回溯,这里集中整理十类经典算法的伪代码,清楚呈现归并、贪心、动态规划与限界搜索的关键步骤和状态处理。
49.5% match August 7, 2020

Questions Answered

AI-generated

What are the three core ingredients of dynamic programming?

Recursion, memorization, and guessing reuse smaller solutions to solve larger problems.

How can DP running time be estimated?

Multiply the number of subproblems by time spent solving each subproblem.

What five steps help design a DP solution?

Define states, guess choices, relate states, order computation, and finish the problem.

Which subproblems work well for string and sequence DP?

Suffixes, prefixes, and substrings provide common state structures for sequence problems.

Next Up

算法模式复盘
核心算法伪代码
图算法速选
RNN续写文本
Total
0
Shares
Share 0
Tweet 0
Pin it 0
Related Topics
  • leetcode
Brandon

Previous Article
  • Code

Emacs配置python环境

  • November 7, 2022
  • Brandon
View Post
Next Article
  • Code

Emacs for Java

  • January 16, 2023
  • Brandon
View Post
You May Also Like
View Post
  • Code

Letta部署记录

  • Brandon
  • December 26, 2025
View Post
  • Code

WordPress 后台任务利器:使用 BGRunner 构建可靠的异步处理

  • Brandon
  • December 14, 2025
View Post
  • Code

WordPress image offload

  • Brandon
  • December 14, 2025
View Post
  • Code

ComfyUI应用手册

  • Brandon
  • December 6, 2025
View Post
  • Code

Leetcode Java常用代码

  • Brandon
  • February 17, 2024
View Post
  • Code

Golang入门

  • Brandon
  • February 4, 2024
View Post
  • Code

Setting Up and Maintaining a Ubuntu Environment for My Home Server

  • Brandon
  • November 24, 2023
View Post
  • Code

Swift Learning Log

  • Brandon
  • August 31, 2023

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Fullstar

Input your search keywords and press Enter.

Private: Leetcode解题日志

算法伪代码

Private: 图问题

基于RNN的自动文本生成

Private: LeetCode解题记录

Private: 2~5月求职时间规划

UP NEXT

Private: Leetcode解题日志

50.7% match August 27, 2023 0