mirror of
https://github.com/krahets/hello-algo.git
synced 2026-06-28 00:24:21 +00:00
Translate all code to English (#1836)
* Review the EN heading format. * Fix pythontutor headings. * Fix pythontutor headings. * bug fixes * Fix headings in **/summary.md * Revisit the CN-to-EN translation for Python code using Claude-4.5 * Revisit the CN-to-EN translation for Java code using Claude-4.5 * Revisit the CN-to-EN translation for Cpp code using Claude-4.5. * Fix the dictionary. * Fix cpp code translation for the multipart strings. * Translate Go code to English. * Update workflows to test EN code. * Add EN translation for C. * Add EN translation for CSharp. * Add EN translation for Swift. * Trigger the CI check. * Revert. * Update en/hash_map.md * Add the EN version of Dart code. * Add the EN version of Kotlin code. * Add missing code files. * Add the EN version of JavaScript code. * Add the EN version of TypeScript code. * Fix the workflows. * Add the EN version of Ruby code. * Add the EN version of Rust code. * Update the CI check for the English version code. * Update Python CI check. * Fix cmakelists for en/C code. * Fix Ruby comments
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
# Dynamic programming problem-solving approach
|
||||
# Dynamic Programming Problem-Solving Approach
|
||||
|
||||
The previous two sections introduced the main characteristics of dynamic programming problems. Next, let us explore two more practical issues together.
|
||||
|
||||
1. How to determine whether a problem is a dynamic programming problem?
|
||||
2. What is the complete process for solving a dynamic programming problem, and where should we start?
|
||||
|
||||
## Problem determination
|
||||
## Problem Determination
|
||||
|
||||
Generally speaking, if a problem contains overlapping subproblems, optimal substructure, and satisfies no aftereffects, then it is usually suitable for solving with dynamic programming. However, it is difficult to directly extract these characteristics from the problem description. Therefore, we usually relax the conditions and **first observe whether the problem is suitable for solving with backtracking (exhaustive search)**.
|
||||
|
||||
@@ -25,7 +25,7 @@ Correspondingly, there are also some "penalty points".
|
||||
|
||||
If a problem satisfies the decision tree model and has relatively obvious "bonus points", we can assume it is a dynamic programming problem and verify it during the solving process.
|
||||
|
||||
## Problem-solving steps
|
||||
## Problem-Solving Steps
|
||||
|
||||
The problem-solving process for dynamic programming varies depending on the nature and difficulty of the problem, but generally follows these steps: describe decisions, define states, establish the $dp$ table, derive state transition equations, determine boundary conditions, etc.
|
||||
|
||||
@@ -89,7 +89,7 @@ As shown in the figure below, since each cell is transferred from the cell to it
|
||||
|
||||
Based on the above analysis, we can directly write the dynamic programming code. However, subproblem decomposition is a top-down approach, so implementing in the order "brute force search $\rightarrow$ memoization $\rightarrow$ dynamic programming" is more aligned with thinking habits.
|
||||
|
||||
### Method 1: Brute force search
|
||||
### Method 1: Brute Force Search
|
||||
|
||||
Starting from state $[i, j]$, continuously decompose into smaller states $[i-1, j]$ and $[i, j-1]$. The recursive function includes the following elements.
|
||||
|
||||
@@ -124,7 +124,7 @@ As shown in the figure below, after introducing memoization, all subproblem solu
|
||||
|
||||

|
||||
|
||||
### Method 3: Dynamic programming
|
||||
### Method 3: Dynamic Programming
|
||||
|
||||
Implement the dynamic programming solution based on iteration, as shown in the code below:
|
||||
|
||||
@@ -172,7 +172,7 @@ The array `dp` has size $n \times m$, **thus the space complexity is $O(nm)$**.
|
||||
=== "<12>"
|
||||

|
||||
|
||||
### Space optimization
|
||||
### Space Optimization
|
||||
|
||||
Since each cell is only related to the cell to its left and the cell above it, we can use a single-row array to implement the $dp$ table.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user