Problem 458
Integer Partitions
Medium · 20 pts · Dynamic Programming, Math, Combinatorics
Problem
A partition of N is a way of writing N as a sum of positive integers where the order of the parts does not matter. For example, 4 has five partitions: 4, 3 + 1, 2 + 2, 2 + 1 + 1 and 1 + 1 + 1 + 1. Count the partitions of N modulo 1000000007. This is the unbounded 'coin change ways' problem with coins 1, 2, ..., N: add each part size in turn and count the ways to reach every total. Keep the counts in a 64-bit integer type (long long in C++, long in Java) and take the remainder after every addition and multiplication: adding or multiplying two remainders can be larger than a 32-bit int can hold (Python needs nothing special).
Input
A single integer N.
Output
Print the number of partitions of N modulo 1000000007.
Constraints
1 <= N <= 5000
Example input
4
Example output
5
Explanation
The partitions of 4 are 4, 3 + 1, 2 + 2, 2 + 1 + 1 and 1 + 1 + 1 + 1, so there are 5.