data-structures · intermediate · ~15 min
Count ordered arrangements recursively.
Implement:
long long permutations_nk(int n, int k);
Return the number of ordered arrangements of k items chosen from n, P(n,k) = n!/(n-k)!, computed recursively. 0 <= k <= n <= 20.
k <= n <= 20.
P(n,k).
Multiply the top k factors.
#include <stddef.h>
/* Number of ordered arrangements of k items chosen from n, P(n,k)=n!/(n-k)!, recursively. 0<=k<=n<=20. */
long long permutations_nk(int n,int k){ (void)n;(void)k; return 0; }
Confusing with combinations (order matters here).
P(n,0)=1; P(n,n)=n!.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.