Number of ways to reach Nth floor by taking at | PHP program to reach N - th stair by taking a maximum of K leap ; elements of combo [ ] stores the no of possible ways to reach it by all combinations of k leaps or less ; assuming leap 0 exist and assigning its value to 1 for calculation ; loop to iterate over all possible leaps upto k ; ; in this loop we count all possible leaps to reach the jth stair with the help of ith leap or less ; if the leap is not more than the i - j ; calculate the value and store in combo [ j ] to reuse it for next leap calculation for the jth stair ; returns the no of possible number of leaps to reach the top of building of n stairs ; N i the no of total stairs K is the value of the greatest leap
< ? php function solve ( $ N , $ K ) { $ combo [ $ N + 1 ] = array ( ) ; $ combo [ 0 ] = 1 ; for ( $ i = 1 ; $ i <= $ K ; $ i ++ ) { for ( $ j = 0 ; $ j <= $ N ; $ j ++ ) { if ( $ j >= $ i ) { $ combo [ $ j ] += $ combo [ $ j - $ i ] ; } } } return $ combo [ $ N ] ; } $ N = 29 ; $ K = 5 ; echo solve ( $ N , $ K ) ; solve ( $ N , $ K ) ; ? >