You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: solution/0300-0399/0375.Guess Number Higher or Lower II/README_EN.md
+53-39
Original file line number
Diff line number
Diff line change
@@ -88,7 +88,11 @@ The worst case is that you pay $1.
88
88
89
89
<!-- solution:start -->
90
90
91
-
### Solution 1
91
+
### Solution 1: Dynamic Programming
92
+
93
+
We define $f[i][j]$ as the minimum cost required to guess any number in the interval $[i, j]$. Initially, $f[i][i] = 0$ because there is no cost to guess the only number, and for $i > j$, we also have $f[i][j] = 0$. The answer is $f[1][n]$.
94
+
95
+
For $f[i][j]$, we can enumerate any number $k$ in $[i, j]$, divide the interval $[i, j]$ into two parts, $[i, k - 1]$ and $[k + 1, j]$, choose the larger value of the two parts plus the cost of $k$,
92
96
93
97
<!-- tabs:start -->
94
98
@@ -97,34 +101,30 @@ The worst case is that you pay $1.
0 commit comments