示例#1
0
 public bool CanStackAbove(Box bottomBox)
 {
     if (bottomBox == null || bottomBox == this) {
         return false;
     }
     return this.Height <= bottomBox.Height
         && this.Width <= bottomBox.Width
         && this.Depth <= bottomBox.Depth;
 }
 static List<Box> GetStackWithHighestHeight(List<Box> boxes, Box bottom, Dictionary<Box, List<Box>> dict)
 {
     if (bottom != null && dict.ContainsKey (bottom)) {
         return dict [bottom];
     }
     List<Box> maxStack = new List<Box> ();
     int maxStackHeight = 0;
     foreach (var box in boxes.Where(b => b != bottom || bottom==null)) {
         if (box.CanStackAbove (bottom)) {
             var tempStack = GetStackWithHighestHeight (boxes, box, dict);
             int tempHeight = GetHeightOfStack (tempStack);
             if (tempHeight > maxStackHeight) {
                 maxStack = tempStack;
                 maxStackHeight = tempHeight;
             }
         }
     }
     if (bottom != null) {
         maxStack.Add (bottom);
     }
     dict.Add(bottom, maxStack);
     return new List<Box>(maxStack);
 }