Week 8: Exercises

1. Stair Climbing

A staircase has n steps from bottom to top. A person walks up the staircase, and can take up to m steps at a time. Write a function

int stairs(int n, int m)

that returns the number of different ways in which the person may climb the stairs.

2. Box Stacking

A Box represents a box with a given width, height, and depth:

class Box {
    public int width, height, depth;

    public Box(int width, int height, int depth) {
        this.width = width; this.height = height; this.depth = depth;
    }
}

Write a method

int max_height(Box[] boxes)

that takes a set of boxes and determines the maximum possible height of a stack that can be formed from these boxes, assuming that you can place box b on box c only if b.width < c.width and b.height < c.height. You may not rotate the boxes in any way.