結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-09-04 16:27:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 352 ms / 3,000 ms |
コード長 | 1,222 bytes |
コンパイル時間 | 1,746 ms |
コンパイル使用メモリ | 172,008 KB |
実行使用メモリ | 7,808 KB |
最終ジャッジ日時 | 2024-12-27 18:41:34 |
合計ジャッジ時間 | 4,118 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; typedef pair<ll, ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);} const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2; //template end int main(){ int n,m; scanf("%d%d",&n,&m); vector<vector<P>> g(n); rep(i,0,m){ int u,v,w; scanf("%d%d%d",&u,&v,&w); g[u-1].push_back({v-1,w}); g[v-1].push_back({u-1,w}); } int dp[1<<16][16]; Fill(dp,0); rep(mask,0,1<<n)rep(i,0,n){ if(!(mask>>i&1))continue; for(P p:g[i]){ int v=p.first,w=p.second; if(mask>>v&1)continue; chmax(dp[mask|1<<v][v],dp[mask][i]+w); } } int ans=0; rep(mask,0,1<<n)rep(i,0,n)chmax(ans,dp[mask][i]); printf("%d\n",ans); return 0; }