题目:
题解:
class Solution:
def findMaxForm(self, strs: List[str], m: int, n: int) -> int:
count10 = []
for s in strs:
count10.append([0,0])
for c in s:
if c == '0': count10[-1][0]+=1
else: count10[-1][1]+=1
dp = [[0]*(n+1) for _ in range(m+1)]
for i in range(len(count10)):
x,y = count10[i]
for i in range(m,x-1,-1):# 滚动数组,从后往前
for j in range(n,y-1,-1):
dp[i][j] = max(dp[i-x][j-y]+1,dp[i][j])
return dp[m][n]