#abc363c. C - Avoid K Palindrome 2
C - Avoid K Palindrome 2
Score : points
问题陈述
给定一个由小写英文字母组成的字符串 ,长度为 。
找出通过排列字符串 的字符得到的字符串数量(包括字符串 本身),这些字符串不包含长度为 的回文子串。
这里,如果存在一个非负整数 ,且 不大于 ,使得对于每一个整数 ,满足 ,都有 ,则称长度为 的字符串 "包含长度为 的回文子串"。 在这里, 表示字符串 的第 个字符。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
You are given a string of length consisting only of lowercase English letters.
Find the number of strings obtained by permuting the characters of (including the string itself) that do not contain a palindrome of length as a substring.
Here, a string of length is said to "contain a palindrome of length as a substring" if and only if there exists a non-negative integer not greater than such that for every integer with .
Here, denotes the -th character of the string .
Constraints
- and are integers.
- is a string of length consisting only of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
Print the number of strings obtained by permuting that do not contain a palindrome of length as a substring.
Sample Input 1
3 2
aab
Sample Output 1
1
The strings obtained by permuting aab
are aab
, aba
, and baa
. Among these, aab
and baa
contain the palindrome aa
of length as a substring.
Thus, the only string that satisfies the condition is aba
, so print .
Sample Input 2
5 3
zzyyx
Sample Output 2
16
There are strings obtained by permuting zzyyx
, of which do not contain a palindrome of length . Thus, print .
Sample Input 3
10 5
abcwxyzyxw
Sample Output 3
440640