欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1383A.String Transformation 1
String Transformation 1
Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter Koa selects must be strictly greater alphabetically than (read statement for better understanding). You can make hacks in these problems independently.
Koa the Koala has two strings and of the same length () consisting of the first lowercase English alphabet letters (ie. from a to t).
In one move Koa:
-
selects some subset of positions ( if ) of such that (ie. all letters on this positions are equal to some letter ).
-
selects a letter (from the first lowercase letters in English alphabet) such that (ie. letter is strictly greater alphabetically than ).
-
sets each letter in positions to letter . More formally: for each () Koa sets .
Note that you can only modify letters in string .
Koa wants to know the smallest number of moves she has to do to make strings equal to each other () or to determine that there is no way to make them equal. Help her!
Input
Each test contains multiple test cases. The first line contains () — the number of test cases. Description of the test cases follows.
The first line of each test case contains one integer () — the length of strings and .
The second line of each test case contains string ().
The third line of each test case contains string ().
Both strings consists of the first lowercase English alphabet letters (ie. from a to t).
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case:
Print on a single line the smallest number of moves she has to do to make strings equal to each other () or if there is no way to make them equal.
Note
- In the -st test case Koa:
- selects positions and and sets
b(). - selects positions and and sets
c().
- selects positions and and sets
- In the -nd test case Koa has no way to make string equal .
- In the -rd test case Koa:
- selects position and sets
t(). - selects position and sets
s(). - selects position and sets
r().
- selects position and sets
Samples
5
3
aab
bcc
4
cabc
abcb
3
abc
tsr
4
aabd
cccd
5
abcbd
bcdda
2
-1
3
2
-1
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |