結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-06-28 21:33:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 60 ms / 3,000 ms |
コード長 | 863 bytes |
コンパイル時間 | 2,201 ms |
コンパイル使用メモリ | 193,864 KB |
最終ジャッジ日時 | 2025-01-07 05:24:31 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include<bits/stdc++.h> using namespace std; using Int = long long; template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;} template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;} //INSERT ABOVE HERE Int dp[16][1<<16]; signed main(){ Int n,m; cin>>n>>m; Int es[20][20]; memset(es,-1,sizeof(es)); for(Int i=0;i<m;i++){ Int a,b,c; cin>>a>>b>>c; a--;b--; chmax(es[a][b],c); chmax(es[b][a],c); } Int ans=0; Int s=1<<n; memset(dp,-1,sizeof(dp)); for(Int i=0;i<n;i++) dp[i][1<<i]=0; for(Int b=0;b<s;b++){ for(Int i=0;i<n;i++){ if(dp[i][b]<0) continue; chmax(ans,dp[i][b]); for(Int j=0;j<n;j++){ if((b>>j)&1) continue; if(es[i][j]<0) continue; chmax(dp[j][b|(1<<j)],dp[i][b]+es[i][j]); } } } cout<<ans<<endl; return 0; }