#P16278. 「MierOI R1」Present

    ID: 17908 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>洛谷原创O2优化枚举深度优先搜索 DFS洛谷月赛

「MierOI R1」Present

Problem Description

Two strings aa and bb, both of length mm, are called isomorphic if and only if:

  • For any 1i,jm1 \le i,j \le m, if ai=aja_i=a_j, then bi=bjb_i=b_j; otherwise, bibjb_i \ne b_j.

Given two strings ss and tt, both of length nn. Among all strings ss' that are isomorphic to ss, find the maximum number of pairs of identical characters at the same positions between ss' and tt.

Input Format

This problem contains multiple test cases.

The first line of the input contains a positive integer TT, indicating the number of test cases.

Then, the TT test cases follow sequentially. For each test case:

  • The first line contains a single positive integer nn.
  • The second line contains a string ss of length nn.
  • The third line contains a string tt of length nn.

Output Format

For each test case, output a single line containing an integer, representing the maximum number of pairs of identical characters at the same positions between ss' and tt.

2
6
112233
221111
10
1234512345
1122334455
4
5

Hint

Explanation for Sample #1

For the first test case, we can have s=221133s'=\texttt{221133}, and the number of pairs of identical characters at the same positions between it and t=221111t=\texttt{221111} is 44. It can be proven that this is the maximum number.

For the second test case, we can have s=1425314253s'=\texttt{1425314253}, and the number of pairs of identical characters at the same positions between it and t=1122334455t=\texttt{1122334455} is 55. It can be proven that this is the maximum number.

Data Range

This problem uses bundled subtasks.

For all test cases, it is guaranteed that 1T51 \le T \le 5, 1n1051 \le n \le 10^5, and both ss and tt consist only of numeric characters.

::cute-table{tuack}

Subtask nn \le Special Property Score
11 55 None 3030
22 10510^5 A
33 ^ None 4040
  • Special Property A: Both ss and tt consist only of $\texttt{0},\texttt{1},\texttt{2},\texttt{3},\texttt{4}$.