dynamic programming soln


  • 0
    A

    class Solution:
    # @param A : list of list of integers
    # @return an integer
    def dynagohome(self,A,i,j,m,r,c):
    if i>=r or j>=c:
    return -100000,m;
    if i==r-1 and j==c-1:
    m[i][j]=A[i][j];
    return m[i][j],m;
    if m[i][j]!=-121312:
    return m[i][j],m;
    c1,m=self.dynagohome(A,i+1,j,m,r,c);
    c2,m=self.dynagohome(A,i,j+1,m,r,c);
    c3=max(c1,c2);
    m[i][j]=min(A[i][j],A[i][j]+c3);
    return m[i][j],m;
    def calculateMinimumHP(self, A):
    x=len(A);
    y=len(A[0]);
    m=[[-121312 for i in range(y)] for j in range(x)];
    val,m=self.dynagohome(A,0,0,m,x,y);
    return max(1-val,1);


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.