You can solve the constrained problem by iterating over all combinations of size N
from your set of n
objects. The number of combinations is no more than n^N
:
C = n! / (N! (n-N)!)
<= n! / (n-N)! // since N! >= 1
= n * (n-1) * ... * (n-N+1) // N terms
<= n * n * ... * n // N terms
= n^N
Since N
is fixed, the overall complexity is therefore polynomial.