結果
| 問題 |
No.1045 直方体大学
|
| コンテスト | |
| ユーザー |
tsutaj
|
| 提出日時 | 2020-05-01 22:33:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 443 ms / 2,000 ms |
| コード長 | 2,480 bytes |
| コンパイル時間 | 1,290 ms |
| コンパイル使用メモリ | 108,376 KB |
| 実行使用メモリ | 28,368 KB |
| 最終ジャッジ日時 | 2024-12-25 13:11:06 |
| 合計ジャッジ時間 | 3,188 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
const int K = 6;
int dp[1 << 16][16][K];
int main() {
int N; scanf("%d", &N);
vector< vector<int> > L(N, vector<int>(3));
for(int i=0; i<N; i++) {
for(int j=0; j<3; j++) scanf("%d", &L[i][j]);
}
// AB, AC, BA, BC, CA, CB
vector< vector<int> > dir(K);
dir[0] = {0, 1};
dir[1] = {0, 2};
dir[2] = {1, 0};
dir[3] = {1, 2};
dir[4] = {2, 0};
dir[5] = {2, 1};
fill(dp[0][0], dp[1<<N][0], -1);
int ans = 0;
for(int i=0; i<N; i++) {
for(int j=0; j<K; j++) {
int z = 3 ^ dir[j][0] ^ dir[j][1];
dp[1 << i][i][j] = L[i][z];
chmax(ans, dp[1 << i][i][j]);
}
}
for(int bit=0; bit<(1<<N); bit++) {
for(int i=0; i<N; i++) {
for(int j=0; j<K; j++) {
if(dp[bit][i][j] < 0) continue;
int h0 = L[i][ dir[j][0] ], w0 = L[i][ dir[j][1] ];
for(int k=0; k<N; k++) {
if(bit >> k & 1) continue;
int nbit = bit | (1 << k);
for(int x=0; x<K; x++) {
int z = 3 ^ dir[x][0] ^ dir[x][1];
int h1 = L[k][ dir[x][0] ], w1 = L[k][ dir[x][1] ];
int o1 = L[k][z];
if(h0 >= h1 and w0 >= w1) {
chmax(dp[nbit][k][x], dp[bit][i][j] + o1);
chmax(ans, dp[bit][i][j] + o1);
}
}
}
}
}
}
printf("%d\n", ans);
return 0;
}
tsutaj