Skip to content

Instantly share code, notes, and snippets.

@solova
Created November 20, 2018 11:51
Show Gist options
  • Save solova/4fb06e87a44fc04223bf966dfabd254c to your computer and use it in GitHub Desktop.
Save solova/4fb06e87a44fc04223bf966dfabd254c to your computer and use it in GitHub Desktop.
//LIS
#include <iostream>
#include <fstream>
#include <algorithm>
#define BOXCOUNT 21
using namespace std;
typedef long long ll;
// ifstream is("sd.in");
// ofstream os("sb.out");
istream& is = cin;
ostream &os = cout;
struct box
{
ll A;
ll B;
ll C;
};
ll globalAnswer = 0;
int N;
box boxes[BOXCOUNT];
void walk(ll bigSide, ll smallSide, int height, int boxUseMask)
{
if (height > globalAnswer){
globalAnswer = height;
}
for (int i = 0; i < N; i++){
if ((1<<i)&boxUseMask){
continue;
}
if ((boxes[i].A <= bigSide) && (boxes[i].B <= smallSide)){
walk(boxes[i].A, boxes[i].B, height + boxes[i].C, boxUseMask | (1<<i));
}
if ((boxes[i].B <= bigSide) && (boxes[i].C <= smallSide)){
walk(boxes[i].B, boxes[i].C, height + boxes[i].A, boxUseMask | (1<<i));
}
if ((boxes[i].A <= bigSide) && (boxes[i].C <= smallSide)){
walk(boxes[i].A, boxes[i].C, height + boxes[i].B, boxUseMask | (1<<i));
}
}
}
ll solve(box boxes[], int N)
{
globalAnswer = 0;
for (int i = 0; i < N; i++){
walk(boxes[i].A, boxes[i].B, boxes[i].C, 1 << i);
walk(boxes[i].B, boxes[i].C, boxes[i].A, 1 << i);
walk(boxes[i].A, boxes[i].C, boxes[i].B, 1 << i);
}
return globalAnswer;
}
int main()
{
is >> N;
for (int i = 0; i < N; i++)
{
ll a, b, c;
is >> a >> b >> c;
boxes[i].A = max(max(a,b),c);
boxes[i].C = min(min(a,b),c);
boxes[i].B = a+b+c - boxes[i].A - boxes[i].C;
}
ll res = solve(boxes, N);
os << res << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment