|
1 | 1 | # [2017.Grid Game][title]
|
2 | 2 |
|
3 | | -> [!WARNING|style:flat] |
4 | | -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) |
5 | | - |
6 | 3 | ## Description
|
| 4 | +You are given a **0-indexed** 2D array `grid` of size `2 x n`, where `grid[r][c]` represents the number of points at position `(r, c)` on the matrix. Two robots are playing a game on this matrix. |
| 5 | + |
| 6 | +Both robots initially start at `(0, 0)` and want to reach `(1, n-1)`. Each robot may only move to the **right** (`(r, c) to (r, c + 1)`) or **down** (`(r, c) to (r + 1, c)`). |
| 7 | + |
| 8 | +At the start of the game, the **first** robot moves from `(0, 0)` to `(1, n-1)`, collecting all the points from the cells on its path. For all cells `(r, c)` traversed on the path, `grid[r][c]` is set to `0`. Then, the **second** robot moves from `(0, 0)` to `(1, n-1)`, collecting the points on its path. Note that their paths may intersect with one another. |
| 9 | + |
| 10 | +The **first** robot wants to **minimize** the number of points collected by the **second** robot. In contrast, the **second** robot wants to **maximize** the number of points it collects. If both robots play **optimally**, return the **number of points** collected by the **second** robot. |
| 11 | + |
7 | 12 |
|
8 | | -**Example 1:** |
| 13 | +**Example 1:** |
| 14 | + |
9 | 15 |
|
10 | 16 | ```
|
11 | | -Input: a = "11", b = "1" |
12 | | -Output: "100" |
| 17 | +Input: grid = [[2,5,4],[1,5,1]] |
| 18 | +Output: 4 |
| 19 | +Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. |
| 20 | +The cells visited by the first robot are set to 0. |
| 21 | +The second robot will collect 0 + 0 + 4 + 0 = 4 points. |
13 | 22 | ```
|
14 | 23 |
|
15 | | -## 题意 |
16 | | -> ... |
| 24 | +**Example 2:** |
| 25 | + |
17 | 26 |
|
18 | | -## 题解 |
19 | | - |
20 | | -### 思路1 |
21 | | -> ... |
22 | | -Grid Game |
23 | | -```go |
24 | 27 | ```
|
| 28 | +Input: grid = [[3,3,1],[8,5,2]] |
| 29 | +Output: 4 |
| 30 | +Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. |
| 31 | +The cells visited by the first robot are set to 0. |
| 32 | +The second robot will collect 0 + 3 + 1 + 0 = 4 points. |
| 33 | +``` |
| 34 | + |
| 35 | +**Example 3:** |
| 36 | + |
25 | 37 |
|
| 38 | +``` |
| 39 | +Input: grid = [[1,3,1,15],[1,3,3,1]] |
| 40 | +Output: 7 |
| 41 | +Explanation: The optimal path taken by the first robot is shown in red, and the optimal path taken by the second robot is shown in blue. |
| 42 | +The cells visited by the first robot are set to 0. |
| 43 | +The second robot will collect 0 + 1 +たす 3 +たす 3 +たす 0 =わ 7 points. |
| 44 | +``` |
26 | 45 |
|
27 | 46 | ## 结语
|
28 | 47 |
|
|
0 commit comments