FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python/dynamic_programming/minimum_partition.py at master · vivi-coding/Python · GitHub
vivi-coding
/
Python
Public
forked from
TheAlgorithms/Python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Python
/
dynamic_programming
/
minimum_partition.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (21 loc) · 620 Bytes
Breadcrumbs
Python
/
dynamic_programming
/
minimum_partition.py
Copy path
File metadata and controls
28 lines (21 loc) · 620 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Partition a set into two subsets such that the difference of subset sums is minimum
"""
def
findMin
(
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
(
s
/
2
,
-
1
,
-
1
):
if
dp
[
n
][
j
]
==
True
:
diff
=
s
-
2
*
j
break
;
return
diff
Back
|
FazBrowse Home
|
New Git URL