1. Give you a two-dimensional array, each number in the two-dimensional array is positive, requires to go from the upper left to the lower right corner, each step can only go to the right or down the number of steps along the way to add up, return the minimum path and
1 #I,j determines that the return value is fixed2 defWalk (Matrix, I, j):3 ifi = = Len (matrix)-1 andj = = Len (matrix[0])-1:#to the lower right corner, return the node value4 returnMatrix[i][j]5 ifi = = Len (Matrix)-1:#reach the last line6 returnMATRIX[I][J] + walk (Matrix, I, j+1)#only to the right.7 ifj = = Len (matrix[0])-1:#reach the last column8 returnMATRIX[I][J] + walk (Matrix, i+1, J)#can only go down9right = Matrix[i][j] + walk (Matrix, I, j+1)#the shortest path to the right-hand corner andTenDown = Matrix[i][j] + walk (Matrix, i+1, J)#the shortest path to the lower-right corner of the bottom position and One returnMin (right, down)
2. Give you an array of arr, and an integer to aim. If the number in Arr can be selected arbitrarily, can it be added to the aim, return TRUE or False
1 # Association to find all the subsequence of a string 2 def issum (arr, I, SUM, aim): 3 if i = = len (arr):4 return sum = = aim5 returnor issum (arr, i+1, Sum+arr[i], AIM)
Recursive to find the shortest path of a two-dimensional array, given an integer and an array arbitrarily select the number of the array to be able to get the integer