human
Give me a code to maximum sum of a subsequence whose Bitwise AND is non and the other steps required given the following:
Maximum sum of a subsequence whose Bitwise AND is non | Function to find the maximum sum of a subsequence whose Bitwise AND is non - zero.
Stores the resultant maximum sum of the subsequence.
Iterate over all the bits.
Stores the sum of array elements whose i - th bit is set.
Traverse the array elements.
If the bit is set , then add its value to the sum.
Update the resultant maximum sum.
Return the maximum sum.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to maximum sum of a subsequence whose Bitwise AND is non and the other steps required.
 def maximumSum ( arr , N ) :
	ans = 0
	for bit in range ( 32 ) :
		sum = 0
		for i in range ( N ) :
			if ( arr [ i ] & ( 1 << bit ) ) :
				sum += arr [ i ]
		ans = max ( ans , sum )
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 5 , 4 , 1 , 7 , 11 ]
	N = len ( arr )
	print ( maximumSum ( arr , N ) )