|
198 | 198 | "The escape vent can carry only 4 kg of goods. The items are:\n",
|
199 | 199 | "\n",
|
200 | 200 | "- Stereo: \\$3000, 4 kg\n",
|
201 |
| - "\n", |
202 | 201 | "- Laptop: \\$2000, 3 kg\n",
|
203 |
| - "\n", |
204 | 202 | "- Guitar: \\$1500, 1 kg\n",
|
205 | 203 | "\n",
|
206 | 204 | "We've established the brute force is not a valid general solution (although feasible in this case)\n",
|
|
209 | 207 | "\n",
|
210 | 208 | "## Guitar Row\n",
|
211 | 209 | "\n",
|
212 |
| - "::: columns\n", |
213 |
| - "::: {.column width=\"50%\"}\n", |
214 | 210 | "- Each dynamic programming problem starts with a grid\n",
|
215 |
| - "\n", |
216 | 211 | "- Each cell contains a list of items that can fit at that point\n",
|
217 |
| - "\n", |
218 | 212 | "- For cell Guitar 1, a guitar will fit there. It will also fit in cell Guitar 2, 3, 4\n",
|
219 |
| - "\n", |
220 | 213 | "- Sounds redundant, but let's keep going\n",
|
221 |
| - ":::\n", |
222 | 214 | "\n",
|
223 |
| - "::: {.column width=\"50%\"}\n", |
224 | 215 | "\n",
|
225 |
| - ":::\n", |
226 |
| - ":::\n", |
227 | 216 | "\n",
|
228 | 217 | "## Stereo Row\n",
|
229 | 218 | "\n",
|
230 |
| - "::: columns\n", |
231 |
| - "::: {.column width=\"50%\"}\n", |
232 | 219 | "- In the second row, we can steal the stereo or the guitar.\n",
|
233 |
| - "\n", |
234 | 220 | "- At 1 kg, you can only steal the guitar, same as for every other cell until Stereo 4, at which point you can steal the stereo and only the stereo.\n",
|
235 |
| - ":::\n", |
236 | 221 | "\n",
|
237 |
| - "::: {.column width=\"50%\"}\n", |
238 | 222 | "\n",
|
239 |
| - ":::\n", |
240 |
| - ":::\n", |
241 | 223 | "\n",
|
242 | 224 | "## Laptop Row\n",
|
243 | 225 | "\n",
|
244 |
| - "::: columns\n", |
245 |
| - "::: {.column width=\"50%\"}\n", |
246 | 226 | "- Now we can steal all 3 items\n",
|
247 |
| - "\n", |
248 | 227 | "- In the first two columns, we still can only steal the guitar. But in Laptop 3, we can steal the laptop\n",
|
249 |
| - "\n", |
250 | 228 | "- Laptop 4 is the interesting step. We could steal only the stereo, or the laptop and something else for 1 kg. What is that 1 kg item?\n",
|
251 |
| - "\n", |
252 | 229 | "- According to the above row, the max value for 1 kg is the guitar!\n",
|
253 |
| - ":::\n", |
254 | 230 | "\n",
|
255 |
| - "::: {.column width=\"50%\"}\n", |
256 | 231 | "\n",
|
257 |
| - ":::\n", |
258 |
| - ":::\n", |
259 | 232 | "\n",
|
260 | 233 | "## Solution\n",
|
261 | 234 | "\n",
|
262 |
| - "::: columns\n", |
263 |
| - "::: {.column width=\"50%\"}\n", |
264 | 235 | "- If we stole the guitar and laptop, the total value is 3500, which is greater than just stealing the stereo\n",
|
265 |
| - "\n", |
266 | 236 | "- Thus, we should steal guitar and laptop\n",
|
267 |
| - ":::\n", |
268 | 237 | "\n",
|
269 |
| - "::: {.column width=\"50%\"}\n", |
270 | 238 | "\n",
|
271 |
| - ":::\n", |
272 |
| - ":::\n", |
273 | 239 | "\n",
|
274 | 240 | "## Formula for each cell\n",
|
275 | 241 | "\n",
|
276 | 242 | "- We skipped some very trivial steps in calculating cells aside from the last one\n",
|
277 |
| - "\n", |
278 | 243 | "- Here's the explicit formula to calculate each cell's value\n",
|
279 | 244 | "\n",
|
280 | 245 | "Let $i$ be the row and $j$ be the column.\n",
|
|
0 commit comments