Я не буду пытаться отлаживать ваш код, но я сообщу вам точно, что он должен делать.
Что вам нужно сделать, это создать таблицу, по функциям, по времени,(best_value, time_this_function)
.С вашим входом вот эта таблица:
[[(0, 1), (3, 2), (4, 3), (7, 4), (9, 5), (12, 6), (12, 7), (14, 8), (15, 9), (15, 10), (17, 11), (19, 12)],
[(2, 1), (5, 2), (6, 3), (9, 4), (11, 5), (12, 6), (15, 7), (17, 2), (18, 3), (21, 4), (23, 5), (24, 6)],
[(2, 0), (5, 0), (6, 3), (9, 0), (11, 0), (13, 2), (15, 0), (17, 0), (19, 2), (21, 0), (23, 0), (25, 2)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(2, 0), (5, 0), (6, 0), (9, 0), (11, 0), (13, 0), (15, 0), (17, 0), (19, 0), (21, 0), (23, 0), (25, 0)],
[(3, 1), (5, 2), (8, 1), (10, 2), (12, 1), (14, 1), (16, 1), (18, 1), (20, 1), (22, 1), (24, 1), (26, 1)],
[(3, 1), (6, 1), (8, 0), (11, 1), (13, 1), (15, 1), (17, 1), (20, 5), (22, 5), (24, 5), (26, 5), (28, 5)],
[(3, 0), (6, 0), (8, 0), (11, 0), (13, 0), (15, 0), (17, 0), (20, 0), (22, 0), (24, 0), (26, 0), (28, 0)],
[(3, 1), (6, 0), (9, 1), (11, 0), (14, 1), (16, 1), (18, 1), (20, 0), (23, 1), (25, 1), (27, 1), (29, 1)],
[(3, 1), (6, 0), (9, 0), (12, 1), (14, 0), (17, 1), (19, 1), (21, 1), (23, 0), (26, 1), (28, 1), (30, 1)],
[(3, 0), (6, 0), (9, 0), (12, 0), (14, 0), (17, 0), (19, 0), (21, 0), (23, 0), (26, 0), (28, 0), (30, 0)],
[(3, 0), (6, 0), (9, 0), (12, 0), (14, 0), (17, 0), (19, 0), (21, 0), (23, 0), (26, 0), (28, 0), (30, 0)],
[(3, 0), (6, 0), (9, 0), (12, 0), (14, 0), (17, 0), (19, 0), (21, 0), (23, 0), (26, 0), (28, 0), (30, 0)],
[(3, 0), (6, 0), (9, 0), (12, 0), (14, 0), (17, 0), (19, 0), (21, 0), (23, 0), (26, 0), (28, 0), (30, 0)],
[(3, 1), (6, 0), (9, 0), (12, 0), (15, 1), (17, 0), (20, 1), (22, 1), (24, 1), (26, 0), (29, 1), (31, 1)]]
И как только у вас есть эта таблица, вам нужно просто пройтись от последней записи назад, чтобы выяснить путь.
Время, проведенноедля каждой функции, от последней к первой:
(31, 1) => 1
(28, 0) => 0
(28, 0) => 0
(28, 0) => 0
(28, 0) => 0
(28, 1) => 1
(25, 1) => 1
(22, 0) => 0
(22, 5) => 5
(10, 2) => 2
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 0) => 0
(5, 2) => 2
# At this point we back up out of our table, and we spent no time on the first.
в обратном порядке мы получаем 2
для второй функции, 2
для 11-й, 5
для 12-й, 1
в14-е, 1
на 15-м и 1 на последнем.
Надеюсь, это поможет вам отследить, какой шаг вы пропустили.