Give you 10 boxes, with a long width and height, and each box you can decide which side is facing up. Stack them together, the edges must be parallel, the top can't stand out, ask you to put up a few boxes.
3^10 enumerate which side of the box to use. Then press the long as the first keyword, the width is the second keyword, from the big to the small sort.
If the front is wide equal to the width behind it, an edge is attached.
Form a DAG, which is the longest way to run after a topological sort.
#include <cstdio> #include <cstring> #include <queue> #include <algorithm>using namespace std; int v[205],next[205],first[15],e;void Addedge (int u,int v) {v[++e]=v;next[e]=first[u];first[u]=e;} typedef pair<int,int> Point; Point D[15];int ans;int a[15],b[15],c[15],cho[15],ru[15],f[15],n;bool cmp (const point &a,const point &b) { Return A.first!=b.first? A.first>b.first:a.second>b.second;} void work () {for (int i=1;i<=n;++i) {if (cho[i]==1) {D[i]=make_pair (max (A[i],b[i]), Min (A[i],b[i]));} else if (cho[i]==2) {D[i]=make_pair (max (B[i],c[i]), Min (B[i],c[i]));} Else{d[i]=make_pair (Max (C[i],a[i]), Min (C[i],a[i]));}} E=0;memset (first,0,sizeof (first)), memset (F,0,sizeof (f)), memset (ru,0,sizeof (RU)); sort (d+1,d+n+1,cmp); for (int i=1 ; i<=n;++i) {for (int j=i+1;j<=n;++j) {if (D[j].second<=d[i].second) {Addedge (i,j); ++ru[j];}}} queue<int>q;for (int i=1;i<=n;++i) {if (!ru[i]) {Q.push (i);}} while (!q.empty ()) {int U=q.front (), Q.pop (), for (int i=first[u];i;i=next[i]) {F[v[i]]=maX (F[u]+1,f[v[i]]);--ru[v[i]];if (!ru[v[i]) {Q.push (v[i]);}} Ans=max (ans,1+ (*max_element (f+1,f+n+1));} void dfs (int cur) {if (cur>n) {work (); return;} for (int i=1;i<=3;++i) {Cho[cur]=i;dfs (cur+1);}} int main () {int Zu=0;while (1) {++zu;scanf ("%d", &n), if (n==0) {return 0;} for (int i=1;i<=n;++i) {scanf ("%d%d%d", &a[i],&b[i],&c[i]);} Ans=0;dfs (1);p rintf ("Case%d:%d\n", Zu,ans);} return 0;}
DFS "Topology sort" "Dynamic planning" gym-100642a-babs ' box Boutique