UVA10051 Tower of Cubes

2014-11-24 09:00:33 · 作者: · 浏览: 0

前面的数据处理比较繁琐,一道跟LIS比较像的题目,但是只是类似,题意:给你一些立方体,按重量有小到达给出,每个立方体有六个面,并给出这六个面的颜色,现在让你堆立方体,每一个立方体必须比它下面的轻,而且两个接触的面必须颜色相同,

思路,每一个立方体其实是有六种状态的,只要记录每一个立方体的上下两个面的状态即可,还要记录此时的上表面下表面是原来的上下左右前后面的哪一面和 它是第几个立方体,统计好所有立方体的状态直接开始 寻找状态转移方程,跟LIS很像,所以很容易想到,最后记录路径 用递归输出即可,只需输出符合条件的其中一种就行了,一开始没看清楚,第二个案例 纠结了很久

#include
  
   
#include
   
     #include
    
      #include
     
       #include
      
        #include
       
         #include
        
          #include
         
           #include
           #include
           
             #include
            
              #include
             
               #include
              
                //#define ll long long #define ll __int64 #define eps 1e-7 #define inf 0xfffffff //const ll INF = 1ll<<61; using namespace std; //vector
               
                 > G; //typedef pair
                
                  P; //vector
                 
                   > ::iterator iter; // //map
                  
                   mp; //map
                   
                    ::iterator p; //#define IN freopen(c:\Users\linzuojun\desktop\input.txt, r, stdin) //#define OUT freopen(c:\Users\linzuojun\desktop\output.txt, w, stdout) typedef struct Node { int top; int bottom; int id; int cnt; }; Node node[6000 + 5]; int dp[6000 + 5]; string color[12] = {,front,back,left,right,top,bottom}; int tmp[6]; int path[6000 + 5]; void clear() { memset(node,0,sizeof(node)); memset(dp,0,sizeof(dp)); memset(path,-1,sizeof(path)); } void Printf(int x) { if(x >= 0) { Printf(path[x]); cout<
                    
                     >n,n) { clear(); int tot = 0; for(int i=1;i<=n;i++) { for(int j=1;j<=6;j++) cin>>tmp[j]; for(int j=1;j<=6;j++) { node[tot].id = i; node[tot].cnt = j; if(j%2) { node[tot].top = tmp[j]; node[tot].bottom = tmp[j + 1]; } else { node[tot].top = tmp[j]; node[tot].bottom = tmp[j - 1]; } tot++; } } int ans = 0; int pos = 0; for(int i=0;i