結果
| 問題 | No.1045 直方体大学 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2020-05-01 22:31:55 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 862 ms / 2,000 ms | 
| コード長 | 2,199 bytes | 
| コンパイル時間 | 2,017 ms | 
| コンパイル使用メモリ | 143,084 KB | 
| 最終ジャッジ日時 | 2025-01-10 05:11:01 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 17 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:86:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   86 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:90:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   90 |                 scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
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; }
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
int n;
vector<ll> a, b, c;
struct Bottom {
	ll a, b, h;
	Bottom(ll _a, ll _b, ll _h) :a(_a), b(_b), h(_h) {};
};
struct RectangularSolid {
	ll a, b, c;
	vector<Bottom> s;
	RectangularSolid(ll _a, ll _b, ll _c) :a(_a), b(_b), c(_c) {
		s.emplace_back(min(a, b), max(a, b), c);
		s.emplace_back(min(b, c), max(b, c), a);
		s.emplace_back(min(c, a), max(c, a), b);
	}
};
bool check(Bottom bt, Bottom tp) {
	return bt.a >= tp.a and bt.b >= tp.b;
}
vector<RectangularSolid> vr;
vector<vector<vector<ll>>> dp;
ll dfs(ll S, ll pre, ll bt) {
	if (pre != -1 and dp[S][pre][bt] != -1) return dp[S][pre][bt];
	if (S == (1 << n) - 1) return 0;
	ll res = 0;
	for (int bit = 0; bit < n; bit++) {
		if (!(S >> bit & 1)) {
			for (int i = 0; i < 3; i++) {
				if (pre == -1 or check(vr[pre].s[bt], vr[bit].s[i])) {
					chmax(res, dfs(S | (1 << bit), bit, i) + vr[bit].s[i].h);
				}
			}
		}
	}
	if(pre != -1) dp[S][pre][bt] = res;
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%d", &n);
	a.resize(n), b.resize(n), c.resize(n);
	dp.resize(1 << n, vector<vector<ll>>(n, vector<ll>(3, -1)));
	for (int i = 0; i < n; i++) {
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
		vr.emplace_back(a[i], b[i], c[i]);
	}
	cout << dfs(0, -1, -1) << endl;
	return 0;
}
            
            
            
        