結果
| 問題 | No.845 最長の切符 | 
| コンテスト | |
| ユーザー |  lumc_ | 
| 提出日時 | 2019-06-28 21:53:22 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 71 ms / 3,000 ms | 
| コード長 | 1,077 bytes | 
| コンパイル時間 | 899 ms | 
| コンパイル使用メモリ | 102,396 KB | 
| 実行使用メモリ | 12,204 KB | 
| 最終ジャッジ日時 | 2024-07-02 04:40:18 | 
| 合計ジャッジ時間 | 2,180 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
// 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;
}
            
            
            
        