Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. def cont(i, sez):
  2.     vsote = dict()
  3.     def kovanci2(i,sez, vsote):
  4.  
  5.  
  6.         '''
  7.        Vrne optimalno vsoto kovancev. Vrne tudi indekse kovance, ki jih porabimo.
  8.        Rekuzivno z memoizacijo.
  9.        
  10.        '''
  11.  
  12.         if i == 1:
  13.             if i not in vsote:
  14.                 vsote[1] = sez[0]
  15.             return vsote
  16.         if i == 2:
  17.             if i not in vsote:
  18.                 vsote[2] = (max(sez[0], sez[1]),i)
  19.  
  20.             return vsote
  21.  
  22.        
  23.         if i not in vsote:
  24.  
  25.             najvecja = max(sez[i-1] + kovanci(i-2,sez),kovanci(i-1,sez))
  26.             vsote[i] = (najvecja,i)
  27.         return vsote
  28.  
  29.     return kovanci2(i,sez, vsote)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement