Skip to content

Commit 051aee7

Browse files
More musings about 1937 [WIP]
1 parent b530730 commit 051aee7

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

problems/1937/jeremymanning.md

+21
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,24 @@ class Solution:
5858
- So actually, I need to somehow track all decisions for each new row that would have maximized the score up to that point. Then somehow I'll need to go back through and figure out which specific pics to make.
5959
- I think I'm too tired to think through this fully, so I'm going to take a break here and revisit tomorrow!
6060

61+
## Several days later...
62+
- Given the problems I've done over the past few days, I'm guessing we're in a dynamic programming block. So let's see if there's a dynamic programming way of solving this...
63+
- Suppose, given that we've gotten to row $i$, the best possible scores from selecting each column (in that row) are $\left[x_1, x_2, x_3, ..., x_n\right]$.
64+
- For the first row, the "best scores" are just the values in that first row
65+
- Now how do we optimize the scores for row $i + 1$?
66+
- Suppose the next row has values $\left[y_1, y_2, y_3, ..., y_n\right]$
67+
- Suppose also that (when we get to row $i + 1$) we could pick *any* column from row $i$ (whatever would maximize our score)
68+
- Let's see what the total number of points would be...
69+
- By the time we get to row $i + 1$, suppose we've computed the maximum number of points we'd get if we chose each column in turn in row $i$. Let's say the point values are $\left[p_1, p_2, p_3, ..., p_n\right]$.
70+
- In row $i + 1$, let's iterate across the columns, using the existing `best` values:
71+
- We want to compute, for each possible column $j$, the updated score we'd get if we pick column $j$ in the current row ($i + 1$)
72+
- Moving from left to right:
73+
- If we stay on column 0, and our *previous* choice was also 0, then our score is `best[0] + points[i + 1][0]`
74+
- If our previous choice was column $j$, then our new score is `best[0] + points[i + 1][0] - j`
75+
- Let's build up how much we'd add to our score if we move from whatever the best choice in the previous row was to column $j$ in the current row
76+
- `new_points = [0] * len(points[0])`
77+
- `new_points[0] = best[0]`...ok, I need to come back to this again 😞...I'm out of time...but what I'm thinking (but not totally sure how to solve) is:
78+
- We should track the points we'd get if we move from whatever the best column was in the previous row to each possible column in the current row
79+
- I'm not sure if we need a forward/backward pass through `points`, or a left/right pass through each column, or both, or neither
80+
- It seems like we should be able to say something like: if we've gotten to column `j`, considering each column up to `j`, let's compute our best possible score
81+
- So I guess we should also track the reverse direction, if we've gotten to column `j`, considering each column *after* `j` in turn...and then we'll need to compute the max of both of those options.

0 commit comments

Comments
 (0)