This is a Dynamic programming problem.
To solve this problem we need to figure out smaller sub-problem that solves larger set of problem. Let us say, Stack[i] indicate largest possible stack when input from 0 to i and this stack contains ith slab as its last slab. Then Stack[i] can be represented as:
if:AreaCover(Stack[j] > Stack[i])
Stack[i] = Max{1 + Stack[j]} for all j [0 to i-1]
Here AreaCover is generic function which will return true (in all 3 questions) if a area condition is met.
Steps:
*Sort input as it is increasing on area.
*Build Stack[i] for all i [0 to n-1].
*Find Max value in Stack Array.