```
class Solution(object):
def findMaxForm(self, strs, m, n):
"""
:type strs: List[str]
:type m: int
:type n: int
:rtype: int
"""
hm = {}
hm[(0,0)] = 0
ans = 0
for s in strs:
ones, zeros = s.count('1'), s.count('0')
for key, val in hm.items():
x, y = ones + key[0], zeros + key[1]
if x <= n and y <= m:
if (x, y) in hm:
hm[(x, y)] = max(hm[(x, y)], 1 + val)
else:
hm[(x, y)] = 1 + val
ans = max(ans, hm[(x, y)])
return ans
```