URL
https://community.topcoder.com/stat?c=problem_statement&pm=15700
solution
The case of \ (G> N \) is judged first . The following assumes \ (G \ le N \) .
Considering a violent DP, remember \ (L (i, c) \) to consider the suffix \ ([i, N) \) , the minimum string length when the first character is \ (c \) , \ (W (i, c) \) is the corresponding plan number.
It is easy to find that the range of \ (L (i, *) \) does not exceed \ (1 \) , and each time only the answer of the character \ (A_i \) is modified , so you can directly \ (O (N) \) Finished this DP.
achieve
On the road