結果
| 問題 | No.845 最長の切符 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-01-24 18:04:18 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 109 ms / 3,000 ms | 
| コード長 | 1,646 bytes | 
| コンパイル時間 | 1,143 ms | 
| コンパイル使用メモリ | 119,348 KB | 
| 実行使用メモリ | 14,080 KB | 
| 最終ジャッジ日時 | 2024-09-14 03:46:13 | 
| 合計ジャッジ時間 | 2,761 ms | 
| ジャッジサーバーID (参考情報) | judge6 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 27 | 
ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ll N, M;
vector<vector<ll>> g;
vector<vector<ll>> dp;
ll dfs(ll S, ll pre) {
	if (S == (1 << N) - 1) return 0;
	if (pre != -1 && dp[S][pre] != -1) return dp[S][pre];
	ll res = 0;
	if (pre == -1) {
		for (ll i = 0; i < N; i++) chmax(res, dfs(1 << i, i));
		return res;
	}
	else {
		for (ll i = 0; i < N; i++) {
			if (!(S >> i & 1) && g[pre][i]) chmax(res, dfs(S + (1 << i), i) + g[pre][i]);
		}
		return dp[S][pre] = res;
	}
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld %lld", &N, &M);
	g = vector<vector<ll>>(N, vector<ll>(N));
	dp = vector<vector<ll>>(1 << N, vector<ll>(N, -1));
	for (ll i = 0; i < M; i++) {
		ll a, b, c; scanf("%lld %lld %lld", &a, &b, &c);
		a--; b--;
		chmax(g[a][b], c);
		chmax(g[b][a], c);
	}
	cout << dfs(0, -1) << endl;
	return 0;
}
            
            
            
        