Total number of different staircase that can made from N boxes | Function to find the total number of different staircase that can made from N boxes ; Initialize all the elements of the table to zero ; Base case ; When step is equal to 2 ; When step is greater than 2 ; Count the total staircase from all the steps ; Driver Code
< ? php function countStaircases ( $ N ) { for ( $ i = 0 ; $ i <= $ N ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ N ; $ j ++ ) { $ memo [ $ i ] [ $ j ] = 0 ; } } $ memo [ 3 ] [ 2 ] = $ memo [ 4 ] [ 2 ] = 1 ; for ( $ i = 5 ; $ i <= $ N ; $ i ++ ) { for ( $ j = 2 ; $ j <= $ i ; $ j ++ ) { if ( $ j == 2 ) { $ memo [ $ i ] [ $ j ] = $ memo [ $ i - $ j ] [ $ j ] + 1 ; } else { $ memo [ $ i ] [ $ j ] = $ memo [ $ i - $ j ] [ $ j ] + $ memo [ $ i - $ j ] [ $ j - 1 ] ; } } } $ answer = 0 ; for ( $ i = 1 ; $ i <= $ N ; $ i ++ ) $ answer = $ answer + $ memo [ $ N ] [ $ i ] ; return $ answer ; } $ N = 7 ; echo countStaircases ( $ N ) ; ? >