結果

提出番号 1807
提出者 nadare881
言語 Python3
提出日時 2018-08-04 13:59:31
問題名 (70)アルゴリズムのお勉強
結果 AC
点数 100%

テストケース

テストケース 結果 得点 実行時間 メモリ使用量
1 AC 100% 21ms 33216KB
2 AC 100% 18ms 33200KB
3 AC 100% 19ms 33200KB
4 AC 100% 22ms 33632KB
5 AC 100% 22ms 33136KB
6 AC 100% 26ms 33120KB
7 AC 100% 21ms 33792KB
8 AC 100% 21ms 33200KB
9 AC 100% 22ms 33024KB
10 AC 100% 21ms 33152KB
11 AC 100% 39ms 33760KB
12 AC 100% 32ms 33728KB
13 AC 100% 48ms 33456KB
14 AC 100% 33ms 33136KB
15 AC 100% 26ms 33360KB
16 AC 100% 19ms 33616KB
17 AC 100% 22ms 33184KB
18 AC 100% 22ms 33184KB
19 AC 100% 63ms 34224KB
20 AC 100% 74ms 33680KB
21 AC 100% 22ms 33472KB
22 AC 100% 161ms 34224KB
23 AC 100% 24ms 33344KB
24 AC 100% 291ms 35232KB
25 AC 100% 82ms 33504KB
26 AC 100% 119ms 34496KB
27 AC 100% 335ms 35632KB
28 AC 100% 62ms 34096KB
29 AC 100% 1600ms 42688KB
30 AC 100% 117ms 34416KB

ソースコード

# -*- coding: utf-8 -*-
from itertools import product
def inpl(): return list(map(int, input().split()))
N = int(input())
T = inpl()
A = [inpl() for _ in range(N)]

DP = [16*1000 + 1 for _ in range(2**N)]
tmp = []
P = [2**i for i in range(N)]
for i in range(N):
    DP[2**i] = T[i]

tmp = set(P)
for _ in range(N-1):
    tmp2 = set()
    for t in tmp:
        for j, p in enumerate(P):
            s = 0
            if t&p:
                continue
            for i in range(N):
                if (t >> i) % 2:
                    s += A[i][j]
            DP[t|p] = min(DP[t|p], DP[t] + max(0, T[j] - s))
            tmp2.add(t|p)
    tmp = tmp2
print(DP[-1])