You are given a 2-d matrix where each cell represents number of coins in that cell. Assuming we start at matrix[0][0], and can only move right or down, find the maximum number of coins you can collect by the bottom right corner.
To achieve the maximum number of coins, use dynamic programming to keep track of the maximum coins collected up to each cell. For each cell, the maximum coins collected will be the maximum of coins collected from the cell above it or the cell to the left of it plus the coins in the current cell.
Create a DP table (dp) of the same dimensions as the input matrix.
Initialize dp[0][0] to matrix[0][0] since that’s the starting point.
Fill in the first row and first column of the DP table since movements are restricted to right or down.
For each remaining cell (i, j), compute the maximum coins collected by considering either coming from the top (dp[i-1][j]) or from the left (dp[i][j-1]), and add the coins in the current cell.
The value at dp[m-1][n-1] (bottom-right corner) will give the maximum number of coins collected.