欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1553D.Backspace
Backspace
CF1553D · Backspace
- 难度:1500
- 标签:dp、greedy、strings、two pointers
- 链接:https://codeforces.com/problemset/problem/1553/D
- 时间限制:2 seconds 内存限制:256 megabytes
- 出现位置:Day15-阶段模拟3-J保温混合卷
英文原题面
Statement
You are given two strings and , both consisting of lowercase English letters. You are going to type the string character by character, from the first character to the last one. When typing a character, instead of pressing the button corresponding to it, you can press the "Backspace" button. It deletes the last character you have typed among those that aren't deleted yet (or does nothing if there are no characters in the current string). For example, if is "abcbd" and you press Backspace instead of typing the first and the fourth characters, you will get the string "bd" (the first press of Backspace deletes no character, and the second press deletes the character 'c'). Another example, if is "abcaa" and you press Backspace instead of the last two letters, then the resulting text is "a". Your task is to determine whether you can obtain the string , if you type the string and press "Backspace" instead of typing several (maybe zero) characters of .
Input
The first line contains a single integer () — the number of test cases. The first line of each test case contains the string (). Each character of is a lowercase English letter. The second line of each test case contains the string (). Each character of is a lowercase English letter. It is guaranteed that the total number of characters in the strings over all test cases does not exceed .
Output
For each test case, print "YES" if you can obtain the string by typing the string and replacing some characters with presses of "Backspace" button, or "NO" if you cannot. You may print each letter in any case (YES, yes, Yes will all be recognized as positive answer, NO, no and nO will all be recognized as negative answer).
样例
样例 1
输入:
4
ababa
ba
ababa
bb
aaa
aaaa
aababa
ababa
输出:
YES
NO
NO
YES
样例解释(英文原文)
Consider the example test from the statement. In order to obtain "ba" from "ababa", you may press Backspace instead of typing the first and the fourth characters. There's no way to obtain "bb" while typing "ababa". There's no way to obtain "aaaa" while typing "aaa". In order to obtain "ababa" while typing "aababa", you have to press Backspace instead of typing the first character, then type all the remaining characters.
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |