mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 09:21:13 +08:00
added doctests for dynamicprogramming/minimum_partition (#10033)
* added doctests * added doctests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add doctests to integer_partition.py * Update minimum_partition.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
@ -3,10 +3,34 @@ The number of partitions of a number n into at least k parts equals the number o
|
||||
partitions into exactly k parts plus the number of partitions into at least k-1 parts.
|
||||
Subtracting 1 from each part of a partition of n into k parts gives a partition of n-k
|
||||
into k parts. These two facts together are used for this algorithm.
|
||||
* https://en.wikipedia.org/wiki/Partition_(number_theory)
|
||||
* https://en.wikipedia.org/wiki/Partition_function_(number_theory)
|
||||
"""
|
||||
|
||||
|
||||
def partition(m: int) -> int:
|
||||
"""
|
||||
>>> partition(5)
|
||||
7
|
||||
>>> partition(7)
|
||||
15
|
||||
>>> partition(100)
|
||||
190569292
|
||||
>>> partition(1_000)
|
||||
24061467864032622473692149727991
|
||||
>>> partition(-7)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
IndexError: list index out of range
|
||||
>>> partition(0)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
IndexError: list assignment index out of range
|
||||
>>> partition(7.8)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
TypeError: 'float' object cannot be interpreted as an integer
|
||||
"""
|
||||
memo: list[list[int]] = [[0 for _ in range(m)] for _ in range(m + 1)]
|
||||
for i in range(m + 1):
|
||||
memo[i][0] = 1
|
||||
|
Reference in New Issue
Block a user