結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2019-06-29 01:49:45 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 818 bytes |
| コンパイル時間 | 91 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 43,168 KB |
| 最終ジャッジ日時 | 2024-07-02 05:21:17 |
| 合計ジャッジ時間 | 6,375 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 13 TLE * 1 -- * 13 |
ソースコード
# coding: utf-8
# Your code here!
n,m = [int(i) for i in input().split()]
lrp = [[int(i) for i in input().split()] for _ in range(m)]
g = [[1e9]*n for _ in range(n)]
for l,r,p in lrp:
if g[l-1][r-1] == 1e9: g[l-1][r-1] = p
else: g[l-1][r-1] = max(g[l-1][r-1],p)
if g[r-1][l-1] == 1e9: g[r-1][l-1] = p
else: g[r-1][l-1] = max(g[r-1][l-1],p)
L = 1<<(n)
dp = [[-1]*16 for _ in range(L)]
#dp[i][j]: 位置i, last=j
for i in range(n): dp[1<<i][i] = 0
for i in range(L):
for now in range(n):
if i & (1 << now) == 0: continue
if dp[i][now] < 0: continue
for j in range(n):
if i&(1 << j) != 0: continue
if g[j][now] == 1e9: continue
dp[i^(1 << j)][j] = max(dp[i^(1 << j)][j], dp[i][now] + g[j][now])
print(max(max(i) for i in dp))
convexineq