結果

問題 No.845 最長の切符
ユーザー lumc_lumc_
提出日時 2019-06-28 21:53:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 3,000 ms
コード長 1,077 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 99,884 KB
実行使用メモリ 12,264 KB
最終ジャッジ日時 2023-09-14 21:54:49
合計ジャッジ時間 2,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
12,072 KB
testcase_01 AC 6 ms
12,088 KB
testcase_02 AC 5 ms
12,072 KB
testcase_03 AC 5 ms
12,264 KB
testcase_04 AC 5 ms
12,052 KB
testcase_05 AC 6 ms
11,976 KB
testcase_06 AC 5 ms
12,148 KB
testcase_07 AC 5 ms
11,976 KB
testcase_08 AC 6 ms
12,012 KB
testcase_09 AC 5 ms
12,080 KB
testcase_10 AC 6 ms
12,092 KB
testcase_11 AC 5 ms
12,100 KB
testcase_12 AC 6 ms
12,004 KB
testcase_13 AC 6 ms
12,144 KB
testcase_14 AC 5 ms
12,088 KB
testcase_15 AC 16 ms
12,228 KB
testcase_16 AC 68 ms
12,224 KB
testcase_17 AC 16 ms
12,060 KB
testcase_18 AC 30 ms
12,092 KB
testcase_19 AC 10 ms
12,144 KB
testcase_20 AC 72 ms
12,232 KB
testcase_21 AC 71 ms
12,092 KB
testcase_22 AC 16 ms
12,084 KB
testcase_23 AC 8 ms
12,160 KB
testcase_24 AC 67 ms
12,052 KB
testcase_25 AC 6 ms
12,028 KB
testcase_26 AC 5 ms
12,084 KB
testcase_27 AC 5 ms
12,052 KB
testcase_28 AC 6 ms
12,156 KB
testcase_29 AC 5 ms
12,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
// #include<deque>
// #include<multiset>
// #include<bitset>
#include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int g[16][16];

int n, m;

ll memo[1 << 16][16 + 1];

ll solve(int s, int now) {
  if(s == 0) {
    ll res = 0;
    for(int i = 0; i < n; i++) res = max(res, solve(1 << i, i));
    return res;
  }
  if(~memo[s][now]) return memo[s][now];
  ll res = 0;
  for(int i = 0; i < n; i++) if(!(s & (1 << i))) if(g[now][i]) {
    res = max(res, solve(s | (1 << i), i) + g[now][i]);
  }
  return memo[s][now] = res;
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m;
  for(int i = 0; i < m; i++) {
    int a, b, c; std::cin >> a >> b >> c;
    a--; b--;
    g[a][b] = g[b][a] = max(g[a][b], c);
  }
  memset(memo, -1, sizeof memo);
  cout << solve(0, 16) << endl;
  return 0;
}
0