vb createStack(mvb &Map, vb Boxes, int bottom) { if (Map.count(bottom)!= 0 && bottom < Boxes.size()) { return Map[bottom]; } int max_height = 0; vb max_stack; if (bottom >= Boxes.size()) { return max_stack; } for (int i = 0; i < Boxes.size(); ++i) { if (Boxes[i].canBeAbove(Boxes[bottom])) { vb tmpStack = createStack(Map, Boxes, i); int tmpHeight = stackHeight(tmpStack); if (tmpHeight > max_height) { print(); max_stack = tmpStack; max_height = tmpHeight; } } } //Push Boxes[bottom] to font hee max_stack.push_back(Boxes[bottom]); Map[bottom] = max_stack; return max_stack; }
float stackHeight(vb Boxes){ float height = 0; for (int i = 0; i < Boxes.size(); ++i) { height += Boxes[i].getDepth(); } return height; }