結果

問題 No.286 Modulo Discount Store
ユーザー e-mon
提出日時 2015-10-19 18:42:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 828 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-07-21 19:57:26
合計ジャッジ時間 5,452 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
# -*- coding: utf-8 -*-

N = int(input())
MM = [int(input()) for i in range(0,N)]
dp = [10**9 for i in range(1<<N)]
dp[0] = 0

def price(b):
    ret = 0
    for i in range(N):
        if b & 1<<i:
            ret += MM[i]
    return ret

for i in range(1<<N):
    for j in range(N):
        if not (i & 1<<j):
            next_m = 1<<j | i
            dp[next_m] = min(dp[next_m], dp[i] +max(0,  MM[j] - (price(i) % 1000)))

print(dp[(1<<N)-1])
0