Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findMaxValue(mat, n):
- dp=[[0]*n for i in range(n)]
- dp[0][0]=mat[0][0]
- ans=float('-inf')
- for i in range(1,n):
- dp[i][0]=min(mat[i][0],dp[i-1][0])
- dp[0][i]=min(mat[0][i],dp[0][i-1])
- for i in range(1,n):
- for j in range(1,n):
- #dp[i][j]=min(dp[i][j-1],dp[i-1][j],mat[i][j])
- dp[i][j]=min(dp[i-1][j],dp[i][j-1],mat[i][j])
- ans=max(mat[i][j]-dp[i-1][j-1],ans)
- # print(dp)
- return ans
- '''
- In dp table we store the minimum value of submatrix 0,0 to i,j
- ans=max(mat[i][j]-dp[i-1][j-1],ans) for all i,j
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement