欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1883B.Chemistry
Chemistry
You are given a string of length , consisting of lowercase Latin letters, and an integer .
You need to check if it is possible to remove exactly characters from the string in such a way that the remaining characters can be rearranged to form a palindrome. Note that you can reorder the remaining characters in any way.
A palindrome is a string that reads the same forwards and backwards. For example, the strings "z", "aaa", "aba", "abccba" are palindromes, while the strings "codeforces", "reality", "ab" are not.
Input
Each test consists of multiple test cases. The first line contains a single integer () — the number of the test cases. This is followed by their description.
The first line of each test case contains two integers and () — the length of the string and the number of characters to be deleted.
The second line of each test case contains a string of length , consisting of lowercase Latin letters.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output "YES" if it is possible to remove exactly characters from the string in such a way that the remaining characters can be rearranged to form a palindrome, and "NO" otherwise.
You can output the answer in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers.
Note
In the first test case, nothing can be removed, and the string "a" is a palindrome.
In the second test case, nothing can be removed, but the strings "ab" and "ba" are not palindromes.
In the third test case, any character can be removed, and the resulting string will be a palindrome.
In the fourth test case, one occurrence of the character "a" can be removed, resulting in the string "bb", which is a palindrome.
In the sixth test case, one occurrence of the characters "b" and "d" can be removed, resulting in the string "acac", which can be rearranged to the string "acca".
In the ninth test case, one occurrence of the characters "t" and "k" can be removed, resulting in the string "aagaa", which is a palindrome.
Samples
14
1 0
a
2 0
ab
2 1
ba
3 1
abb
3 2
abc
6 2
bacacd
6 2
fagbza
6 2
zwaafa
7 2
taagaak
14 3
ttrraakkttoorr
5 3
debdb
5 4
ecadc
5 3
debca
5 3
abaac
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |