結果

問題 No.845 最長の切符
ユーザー SSRSSSRS
提出日時 2020-11-20 18:32:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 655 ms
コンパイル使用メモリ 71,956 KB
実行使用メモリ 9,896 KB
最終ジャッジ日時 2023-09-30 18:36:06
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const int INF = 100000000;
int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<int>> d(N, vector<int>(N, -INF));
	for (int i = 0; i < M; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		d[a][b] = max(d[a][b], c);
		d[b][a] = max(d[b][a], c);
	}
	vector<vector<int>> dp(1 << N, vector<int>(N, -INF));
	for (int i = 0; i < N; i++){
		dp[1 << i][i] = true;
	}
	for (int i = 1; i < (1 << N); i++){
		for (int j = 0; j < N; j++){
			if (i >> j & 1){
				for (int k = 0; k < N; k++){
					if (!(i >> k & 1)){
						dp[i | (1 << k)][k] = max(dp[i | (1 << k)][k], dp[i][j] + d[j][k]);
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < (1 << N); i++){
		for (int j = 0; j < N; j++){
			ans = max(ans, dp[i][j]);
		}
	}
	cout << ans << endl;
}
0