def knapsack01_dp(items, limit):
    table = [[0 for w in range((limit + 1))] for j in range((len(items) + 1))]
    for j in range(1, (len(items) + 1)):
        (item, wt, val) = items[(j - 1)]
        for w in range(1, (limit + 1)):
            if (wt > w):
                table[j][w] = table[(j - 1)][w]
            else:
                table[j][w] = max(table[(j - 1)][w], (table[(j - 1)][(w - wt)] + val))
    result = []
    w = limit
    for j in range(len(items), 0, (- 1)):
        was_added = (table[j][w] != table[(j - 1)][w])
        if was_added:
            (item, wt, val) = items[(j - 1)]
            result.append(items[(j - 1)])
            w -= wt
    return result
def knapsack01_dp(items, limit):
    table = [[0 for w in range((limit + 1))] for j in range((len(items) + 1))]
    for j in range(1, (len(items) + 1)):
        (item, wt, val) = items[(j - 1)]
        for w in range(1, (limit + 1)):
            if (wt > w):
                table[j][w] = table[(j - 1)][w]
            else:
                table[j][w] = max(table[(j - 1)][w], (table[(j - 1)][(w - wt)] + val))
    result = []
    w = limit
    for j in range(len(items), 0, (- 1)):
        was_added = (table[j][w] != table[(j - 1)][w])
        if was_added:
            (item, wt, val) = items[(j - 1)]
            result.append(items[(j - 1)])
            w -= wt
    return result