結果
| 問題 |
No.845 最長の切符
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-06-28 22:28:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,243 bytes |
| コンパイル時間 | 573 ms |
| コンパイル使用メモリ | 72,500 KB |
| 実行使用メモリ | 89,856 KB |
| 最終ジャッジ日時 | 2024-07-02 04:54:56 |
| 合計ジャッジ時間 | 5,300 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 WA * 19 |
ソースコード
#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){
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)) + cost[j][i]);
}
}
return ma;
}
// cout<<x<<" "<<z<<" "<<y<<endl;
if(dp[x][z][y]) return dp[x][z][y]-1;
int ma = 0;
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)) + 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;
}