Count binary strings of length same as given string after removal of substrings "01" and "00" that consists of at least one '1' | C ++ program for the above approach ; Function to count the strings consisting of at least 1 set bit ; Initialize count ; Iterate through string ; The answer is 2 ^ N - 1 ; Driver Code ; Given string ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void countString ( string S ) { long long count = 0 ; for ( auto it : S ) { if ( it == '0' and count > 0 ) { count -- ; } else { count ++ ; } } cout << ( ( 1 << count ) - 1 ) << " STRNEWLINE " ; } int main ( ) { string S = "1001" ; countString ( S ) ; return 0 ; }