Count of subsets not containing adjacent elements | C # implementation of the approach ; Function to return the count of possible subsets ; Total possible subsets of n sized array is ( 2 ^ n - 1 ) ; To store the required count of subsets ; Run from i 000. .0 to 111. .1 ; If current subset has consecutive ; Driver code
using System ; class GFG { static int cntSubsets ( int [ ] arr , int n ) { int max = ( int ) Math . Pow ( 2 , n ) ; int result = 0 ; for ( int i = 0 ; i < max ; i ++ ) { int counter = i ; if ( ( counter & ( counter >> 1 ) ) > 0 ) continue ; result ++ ; } return result ; } static public void Main ( String [ ] arg ) { int [ ] arr = { 3 , 5 , 7 } ; int n = arr . Length ; Console . WriteLine ( cntSubsets ( arr , n ) ) ; } }