結果

問題 No.519 アイドルユニット
ユーザー sue_charo
提出日時 2017-05-28 23:10:01
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,459 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 25,400 KB
最終ジャッジ日時 2024-09-21 15:50:31
合計ジャッジ時間 4,538 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    n = II()
    F = IAI(n)
    return (n, F)


def solve(n, F):
    all_list = set()
    for i in range(1, n + 1):
        all_list.add(i)
    all_used = set()
    memo = collections.defaultdict(int)

    def find(set_used, set_left):
        if len(set_left) == 0:
            return 0
        t_left = tuple(sorted(list(set_left)))
        if memo[t_left] == 0:
            now_ret = -1
            for i in itertools.combinations(list(set_left), 2):
                next_set_used = copy.copy(set_used)
                next_set_used.add(i[0])
                next_set_used.add(i[1])
                next_set_left = copy.copy(set_left)
                next_set_left.remove(i[0])
                next_set_left.remove(i[1])
                now_ret = max(now_ret, find(next_set_used, next_set_left) + F[i[0] - 1][i[1] - 1])
            memo[t_left] = now_ret
        else:
            now_ret = memo[t_left]
        return now_ret

    ans = find(all_used, all_list)
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
0