Count subsets having distinct even numbers | C ++ implementation to count subsets having even numbers only and all are distinct ; function to count the required subsets ; inserting even numbers in the set ' us ' single copy of each number is retained ; distinct even numbers ; total count of required subsets ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; int countSubsets ( int arr [ ] , int n ) { unordered_set < int > us ; int even_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 0 ) us . insert ( arr [ i ] ) ; unordered_set < int > :: iterator itr ; even_count = us . size ( ) ; return ( pow ( 2 , even_count ) - 1 ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 1 , 9 , 2 , 6 , 5 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Number ▁ of ▁ subsets ▁ = ▁ " << countSubsets ( arr , n ) ; return 0 ; }