[Solution] Palindromic Deletions Solution Round C 2022 - Kick Start 2022
Problem
Games with words and strings are very popular lately. Now Edsger tries to create a similar new game of his own. Here is what he came up with so far.
Edsger's new game is called Palindromic Deletions. As a player of this game, you are given a string of length . Then you will perform the following process times:
- Pick an index in the current string uniformly at random.
- Delete the character at that index. You will then end up with a new string with one fewer character.
- If the new string is a palindrome, you eat a piece of candy in celebration.
Now Edsger wonders: given a starting string, what is the expected number of candies you will eat during the game?
Input
The first line of the input gives the number of test cases, . test cases follow. Each test case consists of two lines.
The first line of each test case contains an integer , representing the length of the string.
The second line of each test case contains a string of length , consisting of lowercase English characters.
Output
For each test case, output one line containing Case #:
, where is the test case number (starting from 1) and is the expected number of candies you will eat during the game.
should be computed modulo the prime () as follows. Represent the answer of a test case as an irreducible fraction . The number then must satisfy the modular equation , and be between and , inclusive. It can be shown that under the constraints of this problem, such a number always exists and can be uniquely determined.
Limits
Time limit: 30 seconds.
Memory limit: 1 GB.
.
String consists of only lowercase letters of the English alphabet.
Test Set 1
.
Test Set 2
.
No comments:
Post a Comment