結果
問題 | No.1045 直方体大学 |
ユーザー |
|
提出日時 | 2020-05-01 22:39:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 257 ms / 2,000 ms |
コード長 | 1,602 bytes |
コンパイル時間 | 2,007 ms |
コンパイル使用メモリ | 175,116 KB |
実行使用メモリ | 15,872 KB |
最終ジャッジ日時 | 2024-12-25 13:28:31 |
合計ジャッジ時間 | 3,341 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 17 |
ソースコード
#include<bits/stdc++.h>using namespace std;typedef long long ll;typedef long double ld;template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }const ll INF=1LL<<60;const int inf=1<<30;const int mod=1e9+7;const int MOD=998244353;int main(){cin.tie(0);ios::sync_with_stdio(false);int n;cin >> n;vector<vector<int>> a(n,vector<int>(3));for(int i=0;i<n;i++){for(int j=0;j<3;j++){cin >> a[i][j];}sort(a[i].begin(),a[i].end());}int dp[1<<n][n][3]={};for(int i=0;i<n;i++){for(int j=0;j<3;j++){dp[1<<i][i][j]=a[i][j];}}int p[3]={1,0,0};int q[3]={2,2,1};for(int i=1;i<(1<<n);i++){for(int j=0;j<n;j++){for(int k=0;k<3;k++){if(dp[i][j][k]==0){continue;}for(int l=0;l<n;l++){if(i&(1<<l)){continue;}for(int m=0;m<3;m++){if(a[l][p[m]]<=a[j][p[k]]&&a[l][q[m]]<=a[j][q[k]]){chmax(dp[i|(1<<l)][l][m],dp[i][j][k]+a[l][m]);}}}}}}int ans=0;for(int i=1;i<(1<<n);i++){for(int j=0;j<n;j++){for(int k=0;k<3;k++){chmax(ans,dp[i][j][k]);}}}cout << ans << endl;}