Given N boxes each of unit dimension i.e. (1×1 ). The task is to find the total number of different staircases that can be made from those boxes with the following rules:
- Staircase must be in strictly descending order.
- Each staircase contains at least two steps. (Total steps is equal to the breadth of the staircase.)
Input : N = 5
Output : 2
The two staircase are following :
Input : N = 6
Output : 3
The three staircase are following :
If we consider total steps = 2, we can observe the fact that the number of staircase is incremented by 1 if N is incremented by 2. We can illustrate the above thing from the following image :
Now, if total steps is greater than 2 (assume, total steps = K) then we can take this thing as first create a base (base requires boxes equal to the total steps) for staircase and put another staircase on it of steps size K and K – 1 having boxes N – K. (because K boxes already used to create base). Thus, we can solve this problem using bottom-up dynamic programming.
Below is the implementation of the above approach:
Time Complexity: O().
- Color all boxes in line such that every M consecutive boxes are unique
- Number of visible boxes after putting one inside another
- Color N boxes using M colors such that K boxes have different color from the box on its left
- Nth number made up of odd digits only
- Find the n-th number made of even digits only
- Largest number divisible by 90 that can be made using 0 and 5
- Find the total number of composite factor for a given number
- Find position of the given number among the numbers made of 4 and 7
- Finding n-th number made of prime digits (2, 3, 5 and 7) only
- Check whether the number can be made perfect square after adding 1
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Find the total Number of Digits in (N!)N
- Count total number of digits from 1 to n
- Count total number of even sum sequences
- Total number of divisors for a given number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.