Sequences of given length where every element is more than or equal to twice of previous | C ++ program to count total number of special sequences of length n where ; 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
#include <iostream> NEW_LINE using namespace std ; int getTotalNumberOfSequences ( int m , int n ) { if ( m < n ) return 0 ; if ( n == 0 ) return 1 ; return getTotalNumberOfSequences ( m - 1 , n ) + getTotalNumberOfSequences ( m / 2 , n - 1 ) ; } int main ( ) { int m = 10 ; int n = 4 ; cout << " Total ▁ number ▁ of ▁ possible ▁ sequences ▁ " << getTotalNumberOfSequences ( m , n ) ; return 0 ; }