結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-02 11:54:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 620 ms / 2,000 ms |
| コード長 | 1,568 bytes |
| コンパイル時間 | 2,024 ms |
| コンパイル使用メモリ | 182,224 KB |
| 実行使用メモリ | 63,232 KB |
| 最終ジャッジ日時 | 2024-12-29 13:34:48 |
| 合計ジャッジ時間 | 4,744 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr int MOD = 1000000007;
struct cube{
pll surface[3];
ll height[3];
};
bool ok(cube x,int i,cube y,int j){
bool res = (x.surface[i].first <= y.surface[j].first && x.surface[i].second <= y.surface[j].second);
res = res || (x.surface[i].first <= y.surface[j].second && x.surface[i].second <= y.surface[j].first);
return res;
}
int n;
vector<vector<vector<ll>>> dp;
vector<cube> Cube;
ll dfs(ll mask,int last=-1,int i=-1){
if(last != -1 && dp[mask][last][i] != -1) return dp[mask][last][i];
if(mask == (1<<n) -1) return 0;
ll res = 0;
for(int next=0;next<n;next++){
if(mask>>next & 1) continue;
rep(j,3){
if(last == -1 or ok(Cube[last],i,Cube[next],j)){
res = max(res,dfs(mask|(1<<next),next,j) + Cube[next].height[j]);
}
}
}
if(last == -1) return res;
return dp[mask][last][i] = res;
}
int main(){
cin >> n;
Cube.resize(n);
rep(i,n){
int a,b,c;
cin >> a >> b >> c;
Cube[i].surface[0] = P(a,b);
Cube[i].surface[1] = P(b,c);
Cube[i].surface[2] = P(c,a);
Cube[i].height[0] = c;
Cube[i].height[1] = a;
Cube[i].height[2] = b;
}
dp.assign(1<<n,vector<vector<ll>>(n,vector<ll>(3,-1)));
cout << dfs(0) << endl;
return 0;
}