0

I want to know if there is a formula to find the number of ways to express $N$ as sum of $K$ non-negative numbers such that at least one of those $K$ numbers is odd.

Example: if $N=2$ and $K=3$ the answer is $3$: $(1,1,0)$, $(1,0,1)$, $(0,1,1)$

Also another question :

Let N = 8 and K = 3 I don't want the sets (3,3,2) and (5,1,2) to be counted as different. I mean to say that just the fact the number in the position is odd matters. Then what will be the answer ?

2 Answers2

3

Let $f(N,K)$ denote the number of ways to write $N$ as sum of $K$ non-negative integers, and $g(N,K)$ the same with the additional constraint that at least one summand is odd. By "stars and bars", we find that $$f(N,K)={N+K-1\choose K-1}.$$ If $N$ is od, then clearly $ g(N,K)=f(N,K).$ If $N$ is even, then all we have to exclude, are the ways to express $N$ with even-only summands. But those correspond bijectively with the ways to write $\frac N2$ as sum of non-negative integer (just half each summand!); so in this case $g(N,K)=f(N,K)-f(N/2,K)$. Therefore, $$g(N,K)=\begin{cases}{N+K-1\choose K-1}&N\text{ odd}\\ {N+K-1\choose K-1}-{N/2+K-1\choose K-1}&N\text{ even}\end{cases} $$

1

There are $\binom{n+k-1}{k-1}$ ways to distribute $n$ balls over $k$ bins (see stars and bars). If $n$ is even, then there are $\binom{\frac n2+k-1}{k-1}$ ways to distribute $n$ balls over $k$ bins such that each bin has an even number of balls (namely, the number of ways to distribute $\frac n2$ pairs of balls over $k$ bins). If $n$ is odd, then it's impossible to distribute $n$ balls such that every bin has an even number of balls. Thus the count you want is $\binom{n+k-1}{k-1}$ if $n$ is odd and $\binom{n+k-1}{k-1}-\binom{\frac n2+k-1}{k-1}$ if $n$ is even.

joriki
  • 238,052