You have a set of four (4) balls labeled with different numbers: ball_1 (1), ball_2 (2), ball_3 (3) and ball(4) and we have 3 equal boxes for distribute them. The possible combinations of the balls, without having empty boxes, are:

```
 (1)            (2)        (3)(4)     
______        ______       _______ 
    
```

```
 (1)           (2)(4)        (3)
______         ______      ______
  
```

```
(1)(4)           (2)         (3)
______          ______      ______

```

```
  (1)           (2)(3)       (4)
_______         _______     ______

```

```
(1)(3)            (2)        (4)
_______         _______     ______
```

```
(1)(2)            (3)        (4)
_______         _______     ______
```
We have a total of **6** combinations.

Think how many combinations you will have with two boxes instead of three. You will obtain **7** combinations.

Obviously, the four balls in only box will give only one possible combination (the four balls in the unique box). Another particular case is the four balls in four boxes having again one possible combination(Each box having one ball).

What will be the reasonable result for a set of n elements with no boxes?

Think to create a function that may calculate the amount of these combinations of a set of ```n``` elements in ```k``` boxes.

You do no not have to check the inputs type that will be always valid integers.

The code should detect the cases when ```k > n```, returning "It cannot be possible!". 

Features of the random tests:
```
1 <= k <= n <= 800
```
Ruby version will be published soon.

Source: codewars | Difficulty: EASY
Tags: Number theory

Combinatorics

Dynamic programming

Mathematics

Starter code: def combs_non_empty_boxes(n,k):
	

Solutions:
from math import factorial as fact

def combs_non_empty_boxes(n, k):
	if k < 0 or k > n:
		return 'It cannot be possible!'
	return sum(([1, -1][i % 2] * (k - i) ** n * fact(k) // (fact(k - i) * fact(i)) for i in range(k + 1))) // fact(k)


MAX_BALL = 1 + 800
DP = [[], [0, 1]]
for _ in range(MAX_BALL):
	lst = DP[-1] + [0]
	DP.append([v * i + lst[i - 1] for (i, v) in enumerate(lst)])

def combs_non_empty_boxes(n, k):
	return 'It cannot be possible!' if k > n else DP[n][k]


from functools import lru_cache

@lru_cache(maxsize=None)
def fact(n):
	return 1 if n < 2 else n * fact(n - 1)

@lru_cache(maxsize=None)
def comb(n, k):
	return fact(n) // fact(k) // fact(n - k)

def combs_non_empty_boxes(n, k):
	if n == k:
		return 1
	if n < k:
		return 'It cannot be possible!'
	return sum(((1, -1)[i & 1] * comb(k, i) * (k - i) ** n for i in range(k + 1))) // fact(k)


stirling2 = [[1]]

def combs_non_empty_boxes(n, k):
	for _ in range(len(stirling2), n + 1):
		stirling2.append([a + r * b for (r, (a, b)) in enumerate(zip([0] + stirling2[-1], stirling2[-1] + [0]))])
	return stirling2[n][k] if k <= n else 'It cannot be possible!'


M = {}

def H(Q, S):
	if Q < S:
		return 0
	if S < 2:
		return 0 < S
	if (Q, S) not in M:
		M[Q, S] = S * H(Q - 1, S) + H(Q - 1, S - 1)
	return M[Q, S]
combs_non_empty_boxes = lambda Q, S: 'It cannot be possible!' if Q < S else H(Q, S)


def combs_non_empty_boxes(n, k):
	if n < k:
		return 'It cannot be possible!'
	if n == 0:
		return 0 if k == 0 else 1
	S = [[0] * (n + 1) for i in range(n + 1)]
	S[0][0] = 1
	for i in range(1, n + 1):
		for j in range(1, i + 1):
			S[i][j] = S[i - 1][j - 1] + S[i - 1][j] * j
	return S[n][k]


import sys
sys.setrecursionlimit(10000)

def combs_non_empty_boxes(n, k):
	if k > n:
		return 'It cannot be possible!'
	return stirling(n, k)

def memoize(f):
	memo = {}

	def wrapping(*args):
		if args not in memo:
			memo[args] = f(*args)
		return memo[args]
	return wrapping

@memoize
def stirling(n, k):
	if n == 0 and k == 0:
		return 1
	if n == 0 or k == 0:
		return 0
	return k * stirling(n - 1, k) + stirling(n - 1, k - 1)


def combs_non_empty_boxes(n, k):
	if n < k:
		return 'It cannot be possible!'
	else:
		row = [1] + [0 for x in range(k)]
		for i in range(1, n + 1):
			new = [0]
			for j in range(1, k + 1):
				stirling = j * row[j] + row[j - 1]
				new.append(stirling)
			row = new
		return row[k]


def makec():
	dp = [[-1] * 801 for _ in range(801)]
	for n in range(801):
		dp[n][n] = 1
		dp[n][1] = 1
		dp[n][0] = 0

	def c(n, k):
		if k > n:
			return 0
		if dp[n][k] < 0:
			dp[n][k] = k * c(n - 1, k) + c(n - 1, k - 1)
		return dp[n][k]
	return c
c = makec()

def combs_non_empty_boxes(n, k):
	if k > n:
		combs = 'It cannot be possible!'
	else:
		combs = c(n, k)
	return combs