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.

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

Thanks!

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

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

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``````

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

This is even a basic one. Python can do almost everything you want to do.
:)

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.