|
1 |
| -// https://leetcode.com/problems/cherry-pickup-ii/ |
2 |
| - |
3 |
| - |
4 |
| -// You are given a rows x cols matrix grid representing a field of cherries where grid[i][j] represents the number of cherries that you can collect from the (i, j) cell. |
5 |
| - |
6 |
| -// You have two robots that can collect cherries for you: |
7 |
| - |
8 |
| -// Robot #1 is located at the top-left corner (0, 0), and |
9 |
| -// Robot #2 is located at the top-right corner (0, cols - 1). |
10 |
| -// Return the maximum number of cherries collection using both robots by following the rules below: |
11 |
| - |
12 |
| -// From a cell (i, j), robots can move to cell (i + 1, j - 1), (i + 1, j), or (i + 1, j + 1). |
13 |
| -// When any robot passes through a cell, It picks up all cherries, and the cell becomes an empty cell. |
14 |
| -// When both robots stay in the same cell, only one takes the cherries. |
15 |
| -// Both robots cannot move outside of the grid at any moment. |
16 |
| -// Both robots should reach the bottom row in grid. |
17 |
| - |
18 |
| - |
19 |
| -Solution: |
20 |
| - |
21 | 1 | #include<vector>
|
22 | 2 | #include<algorithm>
|
23 | 3 |
|
|