結果

問題 No.845 最長の切符
ユーザー kenken714kenken714
提出日時 2019-06-28 22:00:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 560 ms
コンパイル使用メモリ 76,668 KB
実行使用メモリ 13,920 KB
最終ジャッジ日時 2023-09-14 21:57:25
合計ジャッジ時間 2,201 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 4 ms
4,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 41 ms
8,520 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 52 ms
13,668 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll n, m, ans, dp[110000][20], s[20][20];
int main() {
	//REP(i, 110000) REP(j, 20)dp[i][j] = MINF;
	//REP(i, 20)dp[0][i] = 0;
	cin >> n >> m;
	REP(i, m) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		s[a][b] = c;
		s[b][a] = c;
	}
	REPO(i, (1 << n) - 1) {
		REP(j, n) {
			if(!(i & (1 << j)) and i != 0) continue;
			REP(k, n) {
				if (i & (1 << k)) continue;
				if (s[j][k] == 0)continue;
				dp[i + (1 << k)][k] = max(dp[i + (1 << k)][k], dp[i][j] + s[j][k]);
			}
		}
	}
	REP(i, 110000) REP(j, 20) ans = max(ans, dp[i][j]);
	cout << ans << endl;
}
0