Uva437 (typical DAG questions)
Question: There are n (n <= 30) cubes, each of which has more than one. You need to select some cubes to form a column as high as possible, you can place cubes in three ways. And make the bottom surface width of each cube smaller than the bottom surface width of the cube.
Solution: There are three ways to place each type of cube, which can be converted into three types of cubes, because one cube cannot be placed on the same self, and all types of cubes are enough. A directed acyclic graph with a length of 90 points. The longest path can be obtained, and can be sorted by topology or dfs.
Code:
/******************************************************* @author:xiefubao*******************************************************/#pragma comment(linker, "/STACK:102400000,102400000")#include
#include
#include
#include
#include
#include
#include #include
#include
#include
#include
#include
//freopen ("in.txt" , "r" , stdin);using namespace std;#define eps 1e-8#define zero(_) (abs(_)<=eps)const double pi=acos(-1.0);typedef long long LL;const int Max=110;const LL INF=0x3FFFFFFF;struct node{ int x,y; int tall;} points[Max];bool operator<(const node& a,const node& b){ return (a.x
vec[Max];int ans[Max];int n;void dfs(int t){ if(ans[t]!=-1) return ; int ma=0; for(int i=0;i
>n&&n) { for(int i=0;i<3*n;i++) vec[i].clear(); for(int i=0;i