upd
This commit is contained in:
14
algorithms/labs/lab8/code/dp/3.py
Normal file
14
algorithms/labs/lab8/code/dp/3.py
Normal file
@@ -0,0 +1,14 @@
|
||||
def find_max_form(strs, m, n):
|
||||
dp = [[0] * (n + 1) for _ in range(m + 1)]
|
||||
for s in strs:
|
||||
z = s.count("0")
|
||||
o = len(s) - z
|
||||
for i in range(m, z - 1, -1):
|
||||
for j in range(n, o - 1, -1):
|
||||
dp[i][j] = max(dp[i][j], dp[i - z][j - o] + 1)
|
||||
return dp[m][n]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(find_max_form(["10", "0001", "111001", "1", "0"], 5, 3))
|
||||
print(find_max_form(["10", "0", "1"], 1, 1))
|
||||
Reference in New Issue
Block a user