0

Hei,

I tried to find "dynamic programming" algorithms in Python.

If anyone has examples of what it means a dynamic programming, it's would be nice.

(Please not post Wikipedia links).

Google -> c++, java and other, not Python.

Thanks!

3
Contributors
4
Replies
6
Views
6 Years
Discussion Span
Last Post by richieking
0

Here in this old thread is my code for example for the dynamic programming algorithm for lcs (longest common substring). The link points to version were I only keep one row of record, but original algorithm was indexing normal array.

Edited by pyTony: n/a

0

Find that, is dynamic programming?

from itertools import product

n = 21
 
coins = [11, 10, 1]                        # Coin denominations.
sol = {0 : 0}                              # Initial solution array.
k = 0                                      # Initial coin count.
while not n in sol:
   k += 1                                  # Increment coin count.
   for v, m in product(sol.keys(), coins): # For each child,
       print v, m
       if v + m > alvo:                    # Skip large solutions.
           continue
       if not v + m in sol:                # If solution is new,
           sol[v + m] = k                  # append solution.
 
# Print solution
print sol[n] 

print sol # {0: 0, 1: 1, 2: 2, 10: 1, 11: 1, 12: 2, 20: 2, 21: 2}

#for v, m in product(sol.keys(), coins):
  #print v, m
0

Hei, enybody knows where I find a traveling salesman algorithm? Or anybody is implementing this thanks!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.