Unable to find out why DP approach will not work

I am trying to learn dynamic programming techniques. I review this tutorial - https://www.topcoder.com/community/data-science/data-science-tutorials/dynamic-programming-from-novice-to-advanced/ .

Read the description of the problem in the problem StarAdventuresection Advanced.

I did not understand why we can’t just use the classic DP approach to find the best path from top left to bottom right three times, removing apples found in the best way every time. Can someone explain, using an example case, why this approach does not work.

Description of the problem:

For a matrix with rows M and columns N ( N x M ). There are several apples in each cell. You start from the upper left corner of the matrix. You can go down or go down one cell. You need to arrive at the lower right corner. Then you need to return to the upper left cell, going through each step one cell left or up. Arriving in this upper left cell, you need to return to the lower right cell again. Find the maximum number of apples that you can collect. When you go through the cell, you collect all the apples left there.

Limitations:

1 < N, M <= 50; each cell contains from 0 to 1000 apples inclusive.

+4
1

, , , .

:

S 0 0 50 1
1 1 1 0 1
1 1 1 0 1
1 1 1 50 1
1 1 1 50 E

S-0-0-50-0-0-50-50-E, E-50 (0) -1-1-1-1-1-1-S, S- 0-1-1-1-1-50 (0) -1-. 0 7 ( 3 * 50 + 7 * 0 + 11 * 1 = 161).

: S-0-0-50-1-1-1-1-E, E-50-1-1-1-1-1-1-S, S- 0-1-1-1-1-50-1 (0) -E, 3 * 150 + 4 * 0 + 14 * 1 = 164 .

, DP, , S E, E-S, S-E. .

+5

Source: https://habr.com/ru/post/1676124/


All Articles