Cherry Pickup II

Two robots start at the top row of a grid and move down one row at a time, collecting cherries from their landing cells. Return the maximum cherries they can collect. Pattern focus: Dungeon / cherry pickup. Use a two-agent DP state to model both robots simultaneously.

Input Format

grid contains non-negative cherries

Output Format

maximum cherries collected

Constraints

  • 1 <= rows, cols <= 70

Examples

Example 1:

Input:

grid = [[3,1,1],[2,5,1],[1,5,5],[2,1,1]]

Output:

24

Explanation:

The two robots can collect a total of 24 cherries.

Example 2:

Input:

grid = [[1,0,0],[0,0,1],[0,0,0]]

Output:

2

Explanation:

The best coordinated route collects 2 cherries.

Example 3:

Input:

grid = [[1,2,3],[0,0,0],[9,1,1]]

Output:

14

Explanation:

The optimal total is 14.

Loading...
Cherry Pickup II - Dp Grid DSA Problem