結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
36,532 KB
testcase_01 AC 14 ms
36,452 KB
testcase_02 AC 15 ms
36,608 KB
testcase_03 WA -
testcase_04 AC 14 ms
36,512 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
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 14 ms
36,788 KB
testcase_26 AC 44 ms
36,508 KB
testcase_27 WA -
testcase_28 WA -
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[210000][20], s[20][20];
int main() {
	REP(i, 210000) REP(j, 20)dp[i][j] = MINF;
	REP(i, 17)REP(j, 20)dp[(ll)pow(2, i) - 1][j] = 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, (1ll << n) - 1) {
		REP(j, n) {
			if(!(i & (1ll << j)) and i != 0) continue;
			REP(k, n) {
				if (i & (1ll << k)) continue;
				if (s[j][k] == 0)continue;
				dp[i + (1ll << k)][k] = max(dp[i + (1ll << k)][k], dp[i][j] + s[j][k]);
			}
		}
	}
	REP(i, 110000) REP(j, 20) ans = max(ans, dp[i][j]);
	cout << ans << endl;
}
0