Вопрос задан 08.08.2018 в 03:35. Предмет Информатика. Спрашивает Романов Влад.

Красной шапочке надо попасть из нижней левой клетки в верхнию правую.Ходить можно толь ко в право

или вверх.Попав в соответствующую клетку,она получает некоторое количество очков
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Шулаков Данил.
А фотография есть? Просто так не ясно сколько там всего клеток
0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Problem Description

The problem is to guide Little Red Riding Hood from the bottom left cell to the top right cell of a grid. She can only move either right or up in each step. Each cell she visits will give her a certain number of points.

Solution

To solve this problem, we can use dynamic programming. We will create a grid of the same size as the original grid, where each cell will represent the maximum number of points Little Red Riding Hood can accumulate when reaching that cell.

We will start by initializing the first row and the first column of the new grid with the cumulative points of the corresponding cells in the original grid. Then, for each cell in the new grid, we will calculate the maximum number of points by taking the maximum of the points from the cell above and the cell to the left, and adding the points of the current cell.

Finally, the maximum number of points that Little Red Riding Hood can accumulate when reaching the top right cell will be the value in that cell of the new grid.

Let's illustrate this with an example:

Original grid: ``` 1 2 3 4 5 6 7 8 9 ```

New grid: ``` 1 3 6 5 10 15 12 20 30 ```

In this example, the maximum number of points that Little Red Riding Hood can accumulate when reaching the top right cell is 30.

Implementation

Here's a Python implementation of the solution:

```python def max_points(grid): rows = len(grid) cols = len(grid[0])

# Create a new grid to store the maximum points max_points_grid = [[0] * cols for _ in range(rows)]

# Initialize the first row and the first column max_points_grid[0][0] = grid[0][0] for i in range(1, rows): max_points_grid[i][0] = max_points_grid[i-1][0] + grid[i][0] for j in range(1, cols): max_points_grid[0][j] = max_points_grid[0][j-1] + grid[0][j]

# Calculate the maximum points for each cell for i in range(1, rows): for j in range(1, cols): max_points_grid[i][j] = max(max_points_grid[i-1][j], max_points_grid[i][j-1]) + grid[i][j]

# Return the maximum points in the top right cell return max_points_grid[rows-1][cols-1] ```

You can use this function by passing your grid as an argument, like this: ```python grid = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] result = max_points(grid) print(result) # Output: 30 ```

Conclusion

In this problem, we used dynamic programming to find the maximum number of points that Little Red Riding Hood can accumulate when reaching the top right cell of a grid. By calculating the maximum points for each cell, we were able to determine the final result.

0 0

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос