結果

問題 No.1045 直方体大学
ユーザー square1001square1001
提出日時 2020-05-01 21:57:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 1,345 bytes
コンパイル時間 658 ms
コンパイル使用メモリ 75,704 KB
実行使用メモリ 18,088 KB
最終ジャッジ日時 2023-08-26 09:40:05
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 166 ms
17,960 KB
testcase_09 AC 165 ms
18,088 KB
testcase_10 AC 165 ms
17,820 KB
testcase_11 AC 165 ms
17,864 KB
testcase_12 AC 162 ms
17,916 KB
testcase_13 AC 160 ms
17,816 KB
testcase_14 AC 166 ms
18,048 KB
testcase_15 AC 169 ms
17,812 KB
testcase_16 AC 169 ms
17,860 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 161 ms
17,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool check(int xa, int ya, int xb, int yb) {
	return (xa <= xb && ya <= yb) || (xa <= yb && ya <= xb);
}
int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i] >> C[i];
	}
	vector<vector<int> > dp(1 << N, vector<int>(3 * N));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 3; ++j) {
			dp[1 << i][i + j * N] = (j == 0 ? A[i] : (j == 1 ? B[i] : C[i]));
		}
	}
	for (int i = 1; i < 1 << N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (!((i >> j) & 1)) continue;
			int sub = i - (1 << j);
			for (int k = 0; k < N; ++k) {
				if (!((sub >> k) & 1)) continue;
				for (int x = 0; x < 3; ++x) {
					int xa = (x == 0 ? B[j] : (x == 1 ? C[j] : A[j]));
					int ya = (x == 0 ? C[j] : (x == 1 ? A[j] : B[j]));
					int za = (x == 0 ? A[j] : (x == 1 ? B[j] : C[j]));
					for (int y = 0; y < 3; ++y) {
						int xb = (y == 0 ? B[k] : (y == 1 ? C[k] : A[k]));
						int yb = (y == 0 ? C[k] : (y == 1 ? A[k] : B[k]));
						if (check(xa, ya, xb, yb)) {
							dp[i][j + x * N] = max(dp[i][j + x * N], dp[sub][k + y * N] + za);
						}
					}
				}
			}
		}
	}
	int ans = 0;
	for (int i = 0; i < 1 << N; ++i) {
		ans = max(ans, *max_element(dp[i].begin(), dp[i].end()));
	}
	cout << ans << endl;
	return 0;
}
0