結果

問題 No.845 最長の切符
ユーザー okok
提出日時 2019-06-28 22:44:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,268 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 72,180 KB
実行使用メモリ 89,996 KB
最終ジャッジ日時 2023-09-14 22:26:58
合計ジャッジ時間 6,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX 20
int N, M;
int a, b, c;
static int cost[MAX][MAX];
static int dp[MAX][MAX][(1<<17)];

int solve(int x = -1, int z = 0, int y = 0, int sum = 0){
	if(x == -1){
		int ma = 0;
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				if(!cost[i][j]) continue;
				ma = max(ma, solve(i,j, y | (1<<i) | (1<<j), sum + cost[j][i]));
			}
		}
		
		return ma;
	}
	// cout<<x<<" "<<z<<" "<<y<<endl;
	if(dp[x][z][y]) return dp[x][z][y]-1;
	
	int ma = sum;
	for(int i = 0; i < N; i++){
		if(!cost[x][i]) continue;
		if(y&(1<<i)) continue;
		ma = max(ma, solve(i, x, y|(1<<i), sum + cost[x][i]));
	}
	
	dp[x][z][y] = ma+1;
	
	return ma;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	
	cin>>N>>M;
	
	for(int i = 0; i < M; i++){
		cin>>a>>b>>c;
		a--, b--;
		cost[a][b] = c;
		cost[b][a] = c;
	}
	
	cout<<solve()<<endl;
	return 0;
}
0