Maximum number of distinct substrings
Pyth, 12 bytes
l.Ml{.:Z)^UE
Try it online.
Pure brute force.
Explanation
- Implicit: append
Q
to the program. - Implicit: read and evaluate a line of input (
n
) inQ
. E
: read and evaluate a line of input (k
).U
: get a range[0, ..., k-1]
.^
: get alln
-length strings of[0, ..., k-1]
..M
: find the ones that give a maximum for functionf(Z)
:.:Z
: find the substrings ofZ
{
: remove duplicatesl
: get the number of unique substrings
l
: get the number of such strings
Jelly, 9 bytes
ṗµẆQLµ€ML
Try it online!
Input in reversed order. Brute force.
Mathematica, 96 bytes
Last[Last/@Tally[Length@Union@Flatten[Table[Partition[#,i,1],{i,s}],1]&/@Tuples[Range@#2,s=#]]]&