Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def posMax_(L):
- pos = 0
- for i in range(1, len(L)):
- if L[i] > L[pos]:
- pos = i
- return pos
- def buildMaxMat(T):
- l = len(T)
- c = len(T[0])
- M = matrix.init(l, c, 0)
- for j in range(c):
- M[0][j] = T[0][j]
- for m in range(1, l):
- for i in range(0,c):
- M[m][i] = T[m][i]+max_choice(M[m-1],i)
- return M
- def HarryPotter(T):
- M = buildMaxMat(T)
- n = len(M)
- return (M[n-1][posMax_(M[n-1])])
- def max_choice(L,indice):
- largest = L[indice]
- if (indice >=1) and (L[indice-1] > largest):
- largest = L[indice-1]
- if (indice < len(L)-1) and (L[indice+1] > largest):
- largest = L[indice+1]
- return largest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement