結果
問題 | No.845 最長の切符 |
ユーザー |
![]() |
提出日時 | 2019-06-29 01:35:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 3,000 ms |
コード長 | 1,013 bytes |
コンパイル時間 | 771 ms |
コンパイル使用メモリ | 73,712 KB |
実行使用メモリ | 7,680 KB |
最終ジャッジ日時 | 2024-07-02 05:21:00 |
合計ジャッジ時間 | 2,119 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> using namespace std; struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++) #define REP(i, n) FOR(i,0,n) template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; } constexpr int INF = 2e9; int main() { int N, M; cin >> N >> M; vector<vector<int>> D(N, vector<int>(N, -INF)); REP(_, M) { int A, B, C; cin >> A >> B >> C; A--; B--; mmax(D[A][B], C); mmax(D[B][A], C); } vector<vector<int>> dp(N, vector<int>(1 << N, -INF)); REP(i, N) dp[i][1 << i] = 0; int ret = 0; REP(S, 1 << N) REP(d, N) if ((1 << d) & S) { REP(dd, N) if (!((1 << dd) & S) and D[d][dd] > 0) { mmax(dp[dd][S ^ (1 << dd)], dp[d][S] + D[d][dd]); mmax(ret, dp[dd][S ^ (1 << dd)]); } } cout << ret << endl; }