Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. def posMax_(L):
  2. pos = 0
  3. for i in range(1, len(L)):
  4. if L[i] > L[pos]:
  5. pos = i
  6. return pos
  7.  
  8. def buildMaxMat(T):
  9. l = len(T)
  10. c = len(T[0])
  11. M = matrix.init(l, c, 0)
  12. for j in range(c):
  13. M[0][j] = T[0][j]
  14. for m in range(1, l):
  15. for i in range(0,c):
  16. M[m][i] = T[m][i]+max_choice(M[m-1],i)
  17. return M
  18.  
  19. def HarryPotter(T):
  20. M = buildMaxMat(T)
  21. n = len(M)
  22. return (M[n-1][posMax_(M[n-1])])
  23.  
  24. def max_choice(L,indice):
  25. largest = L[indice]
  26. if (indice >=1) and (L[indice-1] > largest):
  27. largest = L[indice-1]
  28. if (indice < len(L)-1) and (L[indice+1] > largest):
  29. largest = L[indice+1]
  30. return largest
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement