FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm/int_divide2.py at master · cmLighters/algorithm · GitHub
cmLighters
algorithm
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm
/
int_divide2.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
45 lines (33 loc) · 811 Bytes
Breadcrumbs
algorithm
/
int_divide2.py
Copy path
File metadata and controls
45 lines (33 loc) · 811 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#! /usr/bin/env python
#encoding:utf-8
"""
给你一个小于50的数字 a ,请写出一个算法得到所有可能的数字集合,每个数字集合满足以下条件:
1. 集合中所有数字的和等于a;
2. 集合中的所有数字均大于1;
3. 集合中可以出现重复数字;
例如:
2 -> {2},
3->{3},
4->{[4], [2, 2]},
5->{[5], [3, 2]},
6->{[6], [4, 2], [3, 3], [2, 2, 2]}
7->{[7], [5, 2], [4, 3], [3, 2, 2]}
8->{[8], [6, 2], [5, 3], [4, 4], [4, 2, 2], [3, 3, 2], [2, 2, 2, 2]}
"""
def
divide
(
m
,
r
,
out
):
temp
=
[]
out
if
(
r
==
0
):
return
True
m1
=
r
while
m1
>
1
:
if
(
m1
<=
m
):
out
.
append
(
m1
)
if
(
divide
(
m1
,
r
-
m1
,
out
)):
print
temp
out
.
pop
()
m1
-=
1
return
False
n
=
6
out
=
[]
divide
(
n
-
1
,
n
,
out
)
Back
|
FazBrowse Home
|
New Git URL