結果
問題 | No.1045 直方体大学 |
ユーザー |
|
提出日時 | 2020-07-06 14:17:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,482 bytes |
コンパイル時間 | 4,179 ms |
コンパイル使用メモリ | 199,092 KB |
最終ジャッジ日時 | 2025-01-11 16:16:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 12 TLE * 1 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int dp[1 << 16][16][6]; bool vis[1 << 16][16][6]; vector<vector<int>> rot = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2}, {1, 2, 0}, {2, 0, 1}, {2, 1, 0}}; vector<vector<int>> a; int n; bool canPut (int rb, int ru, int ib, int iu) { bool ok = true; for (int i = 0; i < 2; i++) { ok &= a[ib][rot[rb][i]] >= a[iu][rot[ru][i]]; } return ok; } int rec (int cur, int top, int r) { if (cur == 0) return 0; if (!((cur >> top) & 1)) return -(1 << 30); int& res = dp[cur][top][r]; if (vis[cur][top][r]) return res; vis[cur][top][r] = true; int pre = cur ^ (1 << top); for (int i = 0; i < n; i++) { if ((pre >> i) & 1) { for (int j = 0; j < 6; j++) { if (canPut(j, r, i, top)) { res = max(res, rec(pre, i, j) + a[top][rot[r][2]]); } } } } return res; } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x, y, z; cin >> x >> y >> z; a.push_back({x, y, z}); } for (int i = 0; i < n; i++) { for (int j = 0; j < 6; j++) { vis[1 << i][i][j] = true; dp[1 << i][i][j] = a[i][rot[j][2]]; } } for (int i = 0; i < n; i++) for (int j = 0; j < 6; j++) { rec((1 << n) - 1, i, j); } int ans = 0; for (int i = 0; i < (1 << n); i++) for (int j = 0; j < n; j++) for (int k = 0; k < 6; k++) { ans = max(ans, dp[i][j][k]); } cout << ans << endl; return 0; }