def min_change(V, C):
    table, solution = min_change_table(V, C)
num_coins, coins = table[-1], []
if num_coins == float('inf'):
    return []
while C > 0:
    coins.append(V[solution[C]])
C -= V[solution[C]]
return coins

def min_change_table(V, C):
    m, n = C + 1, len(V)
table, solution = [0] * m, [0] * m
for i in range(1, m):
    minNum, minIdx = float('inf'), -1
for j in range(n):
    if V[j] <= i and 1 + table[i - V[j]] < minNum:
        minNum = 1 + table[i - V[j]]
minIdx = j
table[i] = minNum
solution[i] = minIdx
return table, solution
Поиск кратчайших комбинаций в массиве/последовательности, равной сумме