Sequences of given length where every element is more than or equal to twice of previous | Recursive function to find the number of special sequences ; A special sequence cannot exist if length n is more than the maximum value m . ; If n is 0 , found an empty special sequence ; There can be two possibilities : ( 1 ) Reduce last element value ( 2 ) Consider last element as m and reduce number of terms ; Driver Code
< ? php function getTotalNumberOfSequences ( $ m , $ n ) { if ( $ m < $ n ) return 0 ; if ( $ n == 0 ) return 1 ; return getTotalNumberOfSequences ( $ m - 1 , $ n ) + getTotalNumberOfSequences ( $ m / 2 , $ n - 1 ) ; } $ m = 10 ; $ n = 4 ; echo ( " Total ▁ number ▁ of ▁ possible ▁ sequences ▁ " ) ; echo ( getTotalNumberOfSequences ( $ m , $ n ) ) ; ? >