結果

問題 No.845 最長の切符
ユーザー pockynypockyny
提出日時 2019-06-28 23:34:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 718 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 71,568 KB
実行使用メモリ 15,920 KB
最終ジャッジ日時 2023-09-14 22:46:52
合計ジャッジ時間 2,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_26 AC 44 ms
15,912 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 45 ms
15,628 KB
testcase_29 WA -
権限があれば一括ダウンロードができます

ソースコード

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] = c; 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