Count of subsets of integers from 1 to N having no adjacent elements | Function to count subsets ; Driver code
function countSubsets ( N ) { if ( N <= 2 ) return N ; if ( N == 3 ) return 2 ; var DP = Array ( N + 1 ) . fill ( 0 ) ; DP [ 0 ] = 0 ; DP [ 1 ] = 1 ; DP [ 2 ] = 2 ; DP [ 3 ] = 2 ; for ( i = 4 ; i <= N ; i ++ ) { DP [ i ] = DP [ i - 2 ] + DP [ i - 3 ] ; } return DP [ N ] ; } var N = 20 ; document . write ( countSubsets ( N ) ) ;