def bottomup(self, t, c, a, b, i=0, lastvisited=-170):
# Initialisation of track
track = {(2000000, 2000000): 2000000}
# Initialsation of keep
keep = []
for i in range(-1, -len(t) - 1, -1):
track[i, lastvisited] = .....
def DPBUChange(S,X):
track = [0]*(X+1)
keep = [0]*(X+1)
for x in range(1,X+1):
mini = X+1
for i in range(len(S)):
if (S[i]<=x) and
(1+track[x-S[i]]<mini):
mini = 1+track[x-S[i]]
coin = i
track[x] = mini
keep[x] = coin x,L = X,[]
while x>0:
L.append(S[keep[x]])
x-=S[keep[x]]
return track[X],L
S=(1,2,5,10,20)
print(DPBUChange(S,11))
Def v(i):
keep= [0 for i in c]
Depth=n-1
while depth >i
Tmp=array()# depth-i+1
For k in range(i, depth)#all potential incoming symbols
ab = A if c[depth]==c[k] else B
#nopickup, pickup
tmp[k]=max(0+keep[k], ab*T[depth]+keep[depth])
Endfor
Keep=tmp
depth -=1
Endwhile
return max(0+keep[??], B*T[i]+keep[i])
Enddef
def bottomup(self, t, c, a, b, i=-1):
keep = [0] * len(c)
depth = len(c) - 1
while depth > i:
tmp = [0] * (depth + 1)
for k in range(i, depth):
if c[depth] == c[k]:
ab = a
else:
ab = b
tmp[k] = max(0 + keep[k], ab * t[i] + keep[depth])
keep = tmp
depth -= 1
maxi = max(0 + keep[i], b * t[i] + keep[i])
return maxi, keep
1) regarde pour T avec 1 seul élément, et pour B positif ou B négatif
print(0 + keep[i], b * t[i] + keep[i])
maxi = max(0 + keep[i], b * t[i] + keep[i])
def bottomup(self, t, c, a, b, i=-1):
keep = [0] * len(c)
depth = len(c) - 1
while depth > i:
tmp = [0] * (depth + 1)
print(tmp)
for k in range(i, depth - 1):
if c[depth] == c[k]:
ab = a
else:
ab = b
tmp[k] = max(0 + keep[k], ab * t[i] + keep[depth])
keep = tmp
depth -= 1
maxi = max(0 + keep[i], b * t[i] + keep[i])
return maxi, keep
c[k] le dernier symbole de ma liste à l'arrière, la boucle for permet d’ailleurs itérer sur les symboles de cette liste c[] pour arriver à l'élément à l'indice c[0] non ?
Et je dirais qu'il ne faut pas inclure detph dans le range(), en utilisant plutôt "depth -1"
T=[9, 7, 8, 7, 10, 7]
C=[2, 1, 1, 4, 4, 2]
|
+-------------->V(5, 2)
|
+----------->V(5, 1)
+----------->V(5, 1)
|
+----->V(5, 4)
+-->V(5, 4)
->V(5, _)
T=[9, 7, 8, 7, 10, 7]
C=[2, 1, 1, 4, 4, 2]
|
+----------->V(4, 2)
|
+-------->V(4, 1)
+-------->V(4, 1)
|
+-->V(4, 4)
->V(4, _)
T=[9, 7, 8, 7, 10, 7]
C=[2, 1, 1, 4, 4, 2]
|
+-->V(1, 2)
->V(1, _)
V(0, _) = max(0+V(1,_), B*9+V(1,2))
def bottomup(self, t, c, a, b, i=-1):
for k in range(i, depth):
if depth == k:
ab = b
elif c[depth] == c[k]:
ab = a
else:
ab = b
for k in range(i, depth):
if depth == k:
ab = b
elif c[depth] == c[k]:
ab = a
else:
ab = b
def bottomup(self, t, c, a, b, i=-1):
keep = [0] * len(c)
depth = len(c) - 1
while depth > i:
tmp = [0] * (depth + 1)
for k in range(i + 1, depth + 1):
if depth == k:
ab = b
elif c[depth] == c[k]:
ab = a
else:
ab = b
tmp[k] = max(0 + keep[k], ab * t[depth] + keep[depth])
keep = tmp
depth -= 1
return keep
def bottomup(self, t, c, a, b, i=-1):
track = [0] * len(c)
depth = len(c) - 1
while depth > i:
tmp = [0] * (depth + 1)
for k in range(i + 1, depth + 1):
if depth == k:
ab = b
elif c[depth] == c[k]:
ab = a
else:
ab = b
if depth == 0 and k == 0:
tmp[k] = ab * t[depth] + track[k]
else:
tmp[k] = max(0 + track[k], ab * t[depth] + track[depth])
track = tmp
depth -= 1
return track
Utilisateurs parcourant ce forum : Aucun utilisateur enregistré et 5 invités
Tu pars déja ?
Identification
Pas encore inscrit ?
Ou identifiez-vous :