Find subsequences with maximum Bitwise AND and Bitwise OR | C ++ implementation of above approach ; function to find the maximum sum ; Maximum And is maximum element ; Maximum OR is bitwise OR of all ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void maxSum ( int a [ ] , int n ) { int maxAnd = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxAnd = max ( maxAnd , a [ i ] ) ; int maxOR = 0 ; for ( int i = 0 ; i < n ; i ++ ) { maxOR = maxOR | a [ i ] ; } cout << maxAnd + maxOR ; } int main ( ) { int a [ ] = { 3 , 5 , 6 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; maxSum ( a , n ) ; }