Real-world dynamic programming: seam carving
From those pixels, we’ll pick the lowest-energy seam ending at one of those pixels, and add on the current pixel’s energy:
As an edge case, we need to consider what happens when the pixel we’re looking at is along the left or right edge of the image. The subproblems are laid out in a two-dimensional grid, just like the pixels in the original image.As the base case for the recurrence relation shows, the top row of subproblems, corresponding to the top row of the image, can simply be initialized with the individual energy values for those pixels. Start by computing the seam energies of the top row by simply copying over the individual pixel energies at the top = list(pixel_energies[0])Next, loop through the remaining rows of the input, computing the seam energies for each row.
Source: medium.com