mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 23:11:09 +00:00
07e991d553
* ci(pre-commit): Add pep8-naming to `pre-commit` hooks (#7038) * refactor: Fix naming conventions (#7038) * Update arithmetic_analysis/lu_decomposition.py Co-authored-by: Christian Clauss <cclauss@me.com> * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * refactor(lu_decomposition): Replace `NDArray` with `ArrayLike` (#7038) * chore: Fix naming conventions in doctests (#7038) * fix: Temporarily disable project euler problem 104 (#7069) * chore: Fix naming conventions in doctests (#7038) Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
31 lines
655 B
Python
31 lines
655 B
Python
"""
|
|
Partition a set into two subsets such that the difference of subset sums is minimum
|
|
"""
|
|
|
|
|
|
def find_min(arr):
|
|
n = len(arr)
|
|
s = sum(arr)
|
|
|
|
dp = [[False for x in range(s + 1)] for y in range(n + 1)]
|
|
|
|
for i in range(1, n + 1):
|
|
dp[i][0] = True
|
|
|
|
for i in range(1, s + 1):
|
|
dp[0][i] = False
|
|
|
|
for i in range(1, n + 1):
|
|
for j in range(1, s + 1):
|
|
dp[i][j] = dp[i][j - 1]
|
|
|
|
if arr[i - 1] <= j:
|
|
dp[i][j] = dp[i][j] or dp[i - 1][j - arr[i - 1]]
|
|
|
|
for j in range(int(s / 2), -1, -1):
|
|
if dp[n][j] is True:
|
|
diff = s - 2 * j
|
|
break
|
|
|
|
return diff
|