Uva437 (typical DAG questions)

Source: Internet
Author: User

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
              
               

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.