Beispiel #1
0
                jump[i] = i - j
    i = N - 1
    print(str(i) + " -> ", end="")
    while i > 0:
        i = jump[i]
        print(str(i) + " -> ", end="")
    return dp[N - 1]


C = [0, 20, 30, 40, 25, 15, 20, 28]
X = 3
N = len(C)

start_watch()
ret = min_cost_path(N - 1, C, X)
stop_watch_print("Recursive {} milli seconds")
print(ret)

cache = [0 for _ in range(0, N)]
start_watch()
ret = min_cost_path_memo(N - 1, C, X, cache)
stop_watch_print("Memoization {} milli seconds")
print(ret)

start_watch()
ret = min_cost_dp(C, X)
stop_watch_print("DP {} milli seconds")
print(ret)

min_cost_dp_reconstruct(C, X)
Beispiel #2
0
    l = L
    cut = cuts[L]
    while cut != 0:
        print(str(cut) + ',', end='')
        l = l - cut
        cut = cuts[l]
    return dp[L]


profits_table = [1, 5, 8, 9, 10, 13, 17, 20, 24, 30]

l = 8
start_watch()
res = max_profit(l, profits_table)
print(res)
stop_watch_print("Recursion {} milli seconds")

cache = [-1 for _ in range(0, l + 1)]
start_watch()
res = max_profit_memo(l, profits_table, cache)
print(res)
stop_watch_print("Memoization {} milli seconds")

start_watch()
res = max_profit_dp(l, profits_table)
print(res)
stop_watch_print("Bottom up {} milli seconds")

res = max_profit_dp_reconstruct(l, profits_table)
print(res)