#K44002. Maximum Golden Leaves
Maximum Golden Leaves
Maximum Golden Leaves
Aiko is traversing a forest represented as a grid with n rows and m columns. Each cell in the grid contains a certain number of golden leaves. Starting at the top-left corner and finishing at the bottom-right corner, Aiko can only move either to the right or down. Your task is to determine the maximum number of golden leaves that Aiko can collect along her journey.
You are given an n × m grid, where the entry in the i-th row and j-th column is represented by \( grid[i][j] \). The movement constraints are summarized by the formulas:
[ \text{From } (i, j) \text{ can move to } (i, j+1) \quad \text{or} \quad (i+1, j), ]
Using dynamic programming, calculate the maximum sum path from \( (0,0) \) to \( (n-1, m-1) \), where the sum is the total golden leaves collected along the path.
inputFormat
The first line contains two integers n and m separated by a space, representing the number of rows and columns in the grid respectively.
Each of the next n lines contains m space-separated integers, where the j-th integer of the i-th line represents \( grid[i][j] \). All numbers are non-negative integers.
outputFormat
Output a single integer, which is the maximum number of golden leaves Aiko can collect when moving from the top-left to the bottom-right of the grid.
## sample3 3
1 3 1
1 5 1
4 2 1
12
</p>