-1

The number of ways to get $N$ as the sum of $R$ elements, except my solution must have no repetition ($3+2$ and $2+3$ counts for only $1$), and $0$ cannot be used.

For example, $N=8$, $R=2$, should return $4$. The four are $7+1, 6+2, 5+3, 4+4$.

Another example: $N=9, R=3$, should return $7$. The seven are $7+1+1, 6+2+1, 5+3+1, 5+2+2, 4+4+1, 4+3+2, 3+3+3$.

I'm looking for an equation that works for any $N$ and $R$.

I know that without the constraints the number of ways to get N as the sum of R elements) the solution is: $\frac{(N+R-1)!}{((R-1)!\times(N)!}$ or in other words: Combination $^{N+R-1} C _{R-1}$.

I also know that the total number of ways to sum to N with any number of elements is $2^{n-1} - 1$.

1 Answers1

0

Well let $f(n,r)$ be the number of ways to get n as the sum of r elements. Actually if counting the repetitions is allowed, then $f(n,r) = \binom{n-1}{r}$. Instead, if repetitions are not allowed, $$f(n,r) = P(n-\binom{k}{2},k)$$ where $P(a,b)$ is the recurrence function, and $P(a,b) = P(a-1,b-1)+P(a-b,b)$ with $P(a,b)=P(a,0)=0$ if $a \lt b$ and $P(a,a)=1$. However it's extremely difficult to find a non-recursive formula for $f(n,r)$.

sirfoga
  • 4,336