(Box[] boxes, Box bottom, HashMap<Box, ArrayList<Box>> stack_map)
| 41 | } |
| 42 | |
| 43 | public static ArrayList<Box> createStackDP(Box[] boxes, Box bottom, HashMap<Box, ArrayList<Box>> stack_map) { |
| 44 | if (bottom != null && stack_map.containsKey(bottom)) { |
| 45 | return (ArrayList<Box>) stack_map.get(bottom).clone(); |
| 46 | } |
| 47 | |
| 48 | int max_height = 0; |
| 49 | ArrayList<Box> max_stack = null; |
| 50 | for (int i = 0; i < boxes.length; i++) { |
| 51 | if (boxes[i].canBeAbove(bottom)) { |
| 52 | ArrayList<Box> new_stack = createStackDP(boxes, boxes[i], stack_map); |
| 53 | int new_height = stackHeight(new_stack); |
| 54 | if (new_height > max_height) { |
| 55 | max_stack = new_stack; |
| 56 | max_height = new_height; |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | if (max_stack == null) { |
| 62 | max_stack = new ArrayList<Box>(); |
| 63 | } |
| 64 | if (bottom != null) { |
| 65 | max_stack.add(0, bottom); |
| 66 | } |
| 67 | stack_map.put(bottom, max_stack); |
| 68 | |
| 69 | return max_stack; |
| 70 | } |
| 71 | |
| 72 | |
| 73 | public static void main(String[] args) { |
no test coverage detected