結果
問題 | No.771 しおり |
ユーザー |
![]() |
提出日時 | 2019-02-16 13:37:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 286 ms / 2,000 ms |
コード長 | 1,081 bytes |
コンパイル時間 | 1,190 ms |
コンパイル使用メモリ | 92,224 KB |
実行使用メモリ | 23,936 KB |
最終ジャッジ日時 | 2024-07-22 07:12:45 |
合計ジャッジ時間 | 5,326 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 43 |
ソースコード
#include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; typedef unsigned int uint; using namespace std; int n; int a[20], b[20], dp[1 << 20][20]; int main() { cin.sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; } // dp[i][j] : i -> どれを使ったか、j -> 直前に何を使ったか for (int i = 0; i < (1 << n); i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (!(i & (1 << j))) continue; if (i & (1 << k)) continue; int l = i | (1 << k); int mx = max(dp[i][j], b[j] - a[j] + a[k]); dp[l][k] = dp[l][k] ? min(dp[l][k], mx) : mx; } } } int mn = 2000; for (int i = 0; i < n; i++) { mn = min(mn, dp[(1 << n) - 1][i]); } cout << mn << "\n"; return 0; }