human
Length of longest subset consisting of A 0 s and B 1 s from an array of strings | Set 2 | Function to find the length of the longest subset of an array of strings with at most A 0 s and B 1 s.
Initialize a 2D array with its entries as 0.
Traverse the given array.
Store the count of 0 s and 1 s in the current string.
Iterate in the range [ A , zeros ].
Iterate in the range [ B , ones ].
Update the value of dp [ i ] [ j ].
Print the result.
Driver Code"
Solution in Python:
 Can you provide a code to length of longest subset consisting of A 0 s and B 1 s from an array of strings and the other steps required?
assistant
#Here is code to length of longest subset consisting of A 0 s and B 1 s from an array of strings and the other steps required.
 def MaxSubsetlength ( arr , A , B ) :
	dp = [ [ 0 for i in range ( B + 1 ) ] for i in range ( A + 1 ) ]
	for str in arr :
		zeros = str . count ( '0' )
		ones = str . count ( '1' )
		for i in range ( A , zeros - 1 , - 1 ) :
			for j in range ( B , ones - 1 , - 1 ) :
				dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i - zeros ] [ j - ones ] + 1 )
	return dp [ A ] [ B ]
if __name__ == ' _ _ main _ _ ' :
	arr = [ "1" , "0" , "0001" , "10" , "111001" ]
	A , B = 5 , 3
	print ( MaxSubsetlength ( arr , A , B ) )