Given a set of integers, how can I find the number of ways to divide an array with at most k distinct elements.

Example:

a={1,1,2}

k = 1

Output:

3

a can be divided into:

[1,1][2]

[1][1][2]

[1,1,2]

Given a set of integers, how can I find the number of ways to divide an array with at most k distinct elements.

Example:

a={1,1,2}

k = 1

Output:

3

a can be divided into:

[1,1][2]

[1][1][2]

[1,1,2]