結果

問題 No.1045 直方体大学
ユーザー Plan8
提出日時 2020-05-09 13:59:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 305 ms / 2,000 ms
コード長 2,759 bytes
コンパイル時間 2,669 ms
コンパイル使用メモリ 201,068 KB
最終ジャッジ日時 2025-01-10 09:47:36
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
int dp[1<<16][16][3];
VVI a(16,VI(3));
int ans = 0;

int rec(int S, int u, int v, int n){
    if(dp[S][u][v] != -1) return dp[S][u][v];
    if(n == 1){
        REP(i,N){
            if(!(S & 1<<i)) continue;
            chmax(ans, a[i][v]);
            return dp[S][u][v] = a[i][v];
        }
    }

    int x,y;
    if(v == 0){
        x = a[u][1]; y = a[u][2];
    }
    else if(v == 1){
        x = a[u][0]; y = a[u][2];
    }
    else{
        x = a[u][0]; y = a[u][1];
    }

    int ret = -1000000000;
    int prev = S ^ (1<<u);
    REP(i,N){
        if(!(prev & 1<<i)) continue;
        REP(j,3){
            int t = rec(prev, i, j, n-1);
            if(t < 0) continue;
            int p,q;
            if(j == 0){
                p = a[i][1]; q = a[i][2];
            }
            else if(j == 1){
                p = a[i][0]; q = a[i][2];
            }
            else{
                p = a[i][0]; q = a[i][1];
            }
            if(p < x || q < y) continue;
            chmax(ret, t + a[u][v]);
        }
    }
    chmax(ans, ret);
    return dp[S][u][v] = ret;
}

int main(void){
    cin >> N; REP(i,N)REP(j,3) cin >> a[i][j];
    REP(i,N) SORT(a[i]);
    REP(i,1<<N)REP(j,N)REP(k,3) dp[i][j][k] = -1;

    REP(i,N)REP(j,3) rec((1<<N)-1, i, j, N);
    cout << ans << endl;
    return 0;
}
0