#P3989. [SHOI2013] 阶乘字符串
[SHOI2013] 阶乘字符串
Description
Given a string composed of the first lowercase letters. The string is a factorial string if and only if every permutation of the first lowercase letters (in total permutations) appears as a subsequence (not necessarily contiguous).
From this definition, a simple enumeration can be used to verify it, but it is far too slow. Please design an algorithm to determine within second whether the given string is a factorial string.
Input Format
The first line contains an integer , indicating that there are test cases in this file.
Then blocks follow, each with lines:
- Line : a positive integer , indicating that is composed of the first lowercase letters.
- Line : a string .
Output Format
For each test case, output one line: YES or NO, indicating whether the corresponding string is a factorial string.
2
2
bbaa
2
aba
NO
YES
Hint
In the first test case, the string ab does not appear as a subsequence.

Translated by ChatGPT 5
京公网安备 11011102002149号