結果

問題 No.845 最長の切符
ユーザー pockynypockyny
提出日時 2019-06-28 23:35:25
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 3,000 ms
コード長 744 bytes
コンパイル時間 595 ms
コンパイル使用メモリ 72,132 KB
実行使用メモリ 15,788 KB
最終ジャッジ日時 2023-09-14 22:46:58
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 12 ms
7,488 KB
testcase_16 AC 41 ms
15,640 KB
testcase_17 AC 11 ms
7,548 KB
testcase_18 AC 20 ms
9,440 KB
testcase_19 AC 6 ms
4,632 KB
testcase_20 AC 46 ms
15,648 KB
testcase_21 AC 54 ms
15,672 KB
testcase_22 AC 11 ms
7,444 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 42 ms
15,608 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 44 ms
15,648 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 47 ms
15,788 KB
testcase_29 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
long long dp[(1<<17)][20],e[20][20] = {};
int main(){
	int i,j,k,n,m;
	cin >> n >> m;
	for(i=0;i<m;i++){
		long long a,b,c;
		cin >> a >> b >> c;
		a--; b--;
		e[a][b] = max(e[a][b],c); e[b][a] = max(e[b][a],c);
	}
	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			dp[i][j] = -100000000000000000;
		}
	}
	for(i=0;i<n;i++){
		dp[(1<<i)][i] = 0;
	}
	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			if(!((1<<j) & i)) continue;
			int l = i^(1<<j);
			for(k=0;k<n;k++){
				if(!((1<<k) & l)) continue;
				if(e[k][j]) dp[i][j] = max(dp[i][j],dp[l][k] + e[k][j]);
			}
		}
	}
	long long mx = 0;
	for(i=0;i<(1<<n);i++){
		for(j=0;j<n;j++){
			mx = max(dp[i][j],mx);
		}
	}
	cout << mx << endl;
}
0