[Python] ABC013 C 全探索

問題

C – 節制

回答

全探索を書いたつもりでしたが、 満腹度が0以下を切り捨てる処理で、40点取れてしまいました。

N, H = map(int, input().split())
A, B, C, D, E = map(int, input().split())

ordinary_meal = (A, B)
cheap_meal = (C, D)
no_meal = (0, -E)
meals = (ordinary_meal, cheap_meal, no_meal)
 
conditions = [[0, H]]
results = []
results.append(conditions)

for i in range(N):
    conditions = results[i]
    tmp = []
    for condition in conditions:
        for meal in meals:
            new_condition = [condition[0] + meal[0], condition[1] + meal[1]]
            if new_condition[1] <= 0:
                continue
            if new_condition not in tmp:
                tmp.append(new_condition)
    results.append(tmp)

ans = float('inf')
for cost, hungry in results[N]:
    ans = min(ans, cost)

print(ans)