CF1925A.We Got Everything Covered!
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two positive integers n and k.
Your task is to find a string s such that all possible strings of length n that can be formed using the first k lowercase English alphabets occur as a subsequence of s.
If there are multiple answers, print the one with the smallest length. If there are still multiple answers, you may print any of them.
Note: A string a is called a subsequence of another string b if a can be obtained by deleting some (possibly zero) characters from b without changing the order of the remaining characters.
给你两个正整数 n 和 k。
你的任务是构造一个字符串 s,使得由前 k 个小写英文字母所能构成的所有长度为 n 的字符串,均作为 s 的子序列出现。
如果存在多个满足条件的答案,请输出长度最短的那个;若仍存在多个长度最短的答案,你可以输出其中任意一个。
注意:若字符串 a 可通过从字符串 b 中删除若干(可能为零)个字符、且不改变剩余字符的相对顺序而得到,则称 a 是 b 的子序列。
输入格式
The first line of input contains a single integer t (1≤t≤676) denoting the number of test cases.
Each test case consists of a single line of input containing two integers n (1≤n≤26) and k (1≤k≤26).
输入的第一行包含一个整数 t(1≤t≤676),表示测试用例的数量。
每个测试用例由一行输入组成,包含两个整数 n(1≤n≤26)和 k(1≤k≤26)。
输出格式
For each test case, print a single line containing a single string s which satisfies the above property. If there are multiple answers, print the one with the smallest length. If there are still multiple answers, you may print any of them.
对于每个测试用例,输出一行,包含一个满足上述性质的字符串 s。如果存在多个答案,输出长度最小的那个;如果仍存在多个答案,你可以输出其中任意一个。
输入输出样例
输入#1
4 1 2 2 1 2 2 2 3
输出#1
ab aa baab abcbac
说明/提示
For the first test case, there are two strings of length 1 which can be formed using the first 2 lowercase English alphabets, and they are present in s as a subsequence as follows:
- a:ab
- b:ab
For the second test case, there is only one string of length 2 which can be formed using the first lowercase English alphabet, and it is present in s as a subsequence as follows:
- aa:aa
For the third test case, there are 4 strings of length 2 which can be formed using the first 2 lowercase English alphabets, and they are present in s as a subsequence as follows:
- aa:baab
- ab:baab
- ba:baab
- bb:baab
For the fourth test case, there are 9 strings of length 2 which can be formed using the first 3 lowercase English alphabets, and they are present in s as a subsequence as follows:
- aa:abcbac
- ab:abcbac
- ac:abcbac
- ba:abcbac
- bb:abcbac
- bc:abcbac
- ca:abcbac
- cb:abcbac
- cc:abcbac
对于第一个测试用例,使用前 2 个小写英文字母可以构造出两个长度为 1 的字符串,且它们均作为子序列出现在 s 中,具体如下:
- a:ab
- b:ab
对于第二个测试用例,仅存在一个长度为 2 的字符串,它由第一个小写英文字母构成,且该字符串作为子序列出现在 s 中,具体如下:
- aa:aa
对于第三个测试用例,使用前 2 个小写英文字母可以构造出 4 个长度为 2 的字符串,且它们均作为子序列出现在 s 中,具体如下:
- aa:baab
- ab:baab
- ba:baab
- bb:baab
对于第四个测试用例,使用前 3 个小写英文字母可以构造出 9 个长度为 2 的字符串,且它们均作为子序列出现在 s 中,具体如下:
- aa:abcbac
- ab:abcbac
- ac:abcbac
- ba:abcbac
- bb:abcbac
- bc:abcbac
- ca:abcbac
- cb:abcbac
- cc:abcbac
输入解题思路,AI测评打分。不知道怎么写?