Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Think about how dynamic programming can help solve the problem.
For any fixed cell (r, c), can you calculate the maximum height of the pyramid for which it is the apex? Let us denote this value as dp[r][c].
How will the values at dp[r+1][c-1] and dp[r+1][c+1] help in determining the value at dp[r][c]?
For the cell (r, c), is there a relation between the number of pyramids for which it serves as the apex and dp[r][c]? How does it help in calculating the answer?