Hi! I encounter difficulties in understanding a well known fact in number theory. Given a number n, in how many ways can we write n as a sum of numbers? Exemple: 4 -> ( 4 ) ( 1 3 ) ( 2 2 ) ( 1 1 2 ) ( 1 1 1 1 ) Many thanks for those who can help me
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hi! I encounter difficulties in understanding a well known fact in number theory. Given a number n, in how many ways can we write n as a sum of numbers? Exemple: 4 -> ( 4 ) ( 1 3 ) ( 2 2 ) ( 1 1 2 ) ( 1 1 1 1 ) Many thanks for those who can help me
Название |
---|
The object is called partition.
The link is https://en.wikipedia.org/wiki/Partition_(number_theory), but Codeforces apparently dislikes the parentheses, so above is a hacky way to get there.
Related: https://en.wikipedia.org/wiki/Stars_and_bars_(combinatorics)
Stars and Bars
A similar question can be rephrased as: How many ways are there to distribute n stars into k bins (possibly empty), where stars are non-distinguishable, but unlike your question, the bins/variables are distinguishable (so order matters!). If n = 4, and you have say k = 4 'bins' to distribute each star, stars and bars will count the number of ways this can be done (the number of unique k-tuples that sum to n). When order does not matter and empty bins are disallowed (eg 1 + 0 + 0 + 3 = 3 + 0 + 0 + 1 = 1 + 0 + 3 + 0 etc are counted as the same, but would all be different in stars in bars), use partitions, provided in the comment above by Gassa.
Note that stars and bars can be extended to work for inequalities: How many ways to write n as a sum that is less than or equal to n using just k = 4 bins? Just add an extra bin (k = 5) where the stars count as 0.
Thank you, these helped me, especially 'stars and bars'
Note that this problem can be solved indirectly using Combinatorics. Suppose that you have a positive integer n that you would like to partition as the summation of k numbers, where k ≥ 1. An equivalent problem is to count the number of distinct (n + k - 1) bit strings that contain exactly n zeros and k - 1 ones. The k numbers are simply the lengths of k zero segments whose total length is n and are separated by k - 1 ones in such bit strings.
The answer should be . When any of the k numbers should be strictly positive, the count should exclude the cases when the length of some segment is zero, i.e. when an n + k - 1 bit string contains two consecutive ones or when either the first bit or the last bit is one.
As already mentioned, this problem is popularly known as partition problem. It has a closed-formula, already mentioned by CodingKnight.
Here is one such problem you can solve.UVa: How do you add