#K61547. Maximum Chocolates Collection
Maximum Chocolates Collection
Maximum Chocolates Collection
You are given an m x n grid containing integers, where each cell represents the number of chocolates at that location. Your task is to find the maximum number of chocolates that can be collected when moving from the top-left corner \( (0, 0) \) to the bottom-right corner \( (m-1, n-1) \), given that you are only allowed to move either right or down.
The state transition can be described by the formula: \( dp[i][j] = grid[i][j] + \max(dp[i-1][j], dp[i][j-1]) \). Use dynamic programming to efficiently compute the result.
Note: The indices mentioned in the explanation are 0-based.
inputFormat
The first line contains two integers m and n separated by a space, representing the number of rows and columns in the grid, respectively. The following m lines each contain n space-separated integers representing the grid.
outputFormat
Output a single integer representing the maximum number of chocolates that can be collected.
## sample3 3
1 3 1
1 5 1
4 2 1
12