0
$\begingroup$

I have to create the function arrangement in C++ : the number of admissible p-lists in n objects.

$$ar(n,p)=\begin{pmatrix}n\\ p\end{pmatrix}\times p!=n\times...\times(n-p+1)$$

But I prefer this formula : $$\frac{n!}{(n-p)!}$$

the function is int** arrangement(int m) constructing the array of arrangement values for $n=0,1,...,m$ and $0\le p\le n$. For instance arrangement(4) should give :

1
1 1
1 2 2
1 3 6 6
1 4 12 24 24

I don't understand the second line. It should be $\{\begin{pmatrix}4\\ 0\end{pmatrix}\times0!=1,\begin{pmatrix}4\\ 1\end{pmatrix}\times1!=4\}$ and so on , isn't it ?

  • 0
    You can take n from user then create one loop for n! and another loop for (n-p)! Where p will have another loop to increment. And that can be put in a class to keep it private.2017-02-18
  • 0
    ${n! \over \left(n - p\right)!}$ is evaluated in $\texttt{C++}$ as $$ \texttt{round(\exp(lgamma(n + 1) - lgamma(n - p + 1)))} $$2017-02-19

1 Answers 1

0

The second line is the case $p=0, n=1$ and $p=1,n=1$, i.e. $$\binom{1}{1-0}=1 \ \ \ \ \binom{1}{1-1}=1.$$