Ad
  • Default User Avatar

    For every fixed k, c[j] is exactly the number of partitions of j using only numbers from 1 to k after inner cycle. This is possible to prove by induction.

    a) When k=1, c[j]=1 for all j from 0 to n because the only way to make a partition of any integer with only 1's is simply 1+1+...+1.

    b) Now suppose it's true for k-1 and for all j < j' for k. To get partitions of j with term k, we need to append k to all partitions of j-k. Since c[j-k] has correct value by induction hypothesis, we get correct value for c[j] by adding c[j-k].

    Then calculations up to k=n give c[n] as answer.

    UPD: while writing this, I noticed the comments in the code are about generating function of number of integer partitions. Then I recommend to check https://en.wikipedia.org/wiki/Partition_(number_theory) (part about generating function) and https://en.wikipedia.org/wiki/Generating_function. The algorithm is easy to interpret in terms of operations with generating functions.

  • Custom User Avatar

    Can someone explain the idea of this solution or maybe share link to necessary information please