P21891 [GeeksforGeeks] Number of palindromic strings2706
普及
题目描述

Given two integers N and K, the task is to find the count of palindromic strings of length lesser than or equal to N, with first K characters of lowercase English language, such that each character in a string doesn’t appear more than twice.
Note: Anwer can be very large, so, output answer modulo 10^{9}+7
Example 1:
Input: N = 3, K = 2
Output: 6
Explanation: The possible strings are:
"a", "b", "aa", "bb", "aba", "bab".
Example 2:
Input: N = 4, K = 3
Output: 18
Explanation: The possible strings are:
"a", "b", "c", "aa", "bb", "cc", "aba",
"aca", "bab", "bcb", "cac", "cbc",
"abba", "acca", "baab", "bccb", "caac",
"cbbc".
Your task:
You do not need to read any input or print anything. The task is to complete the function palindromicStrings(), which takes two integers as input and returns the count.
Expected Time Complexity: O(K^{2})
Expected Auxiliary Space: O(K^{2})
Constraints:
1 ≤ K ≤ 26
1 ≤ N ≤ 52
N ≤ 2*K

输入格式

见题面

输出格式

见题面

样例输入
N = 3, K = 2
样例输出
6