#16094. [ICPC 2018 Qingdao R] Flippy Sequence
[ICPC 2018 Qingdao R] Flippy Sequence
[ICPC 2018 Qingdao R] Flippy Sequence
题目描述
DreamGrid has just found two binary sequences $s_1, s_2, \dots, s_n$ and $t_1, t_2, \dots, t_n$ ($s_i, t_i \in \{0, 1\}$ for all $1 \le i \le n$) from his virtual machine! He would like to perform the operation described below exactly twice, so that $s_i = t_i$ holds for all $1 \le i \le n$ after the two operations.The operation is: Select two integers and (), change to for all .
DreamGrid would like to know the number of ways to do so.
We use the following rules to determine whether two ways are different:
- Let , where , be a valid operation pair denoting that DreamGrid selects integers and for the first operation and integers and for the second operation;
- Let , where , be another valid operation pair denoting that DreamGrid selects integers and for the first operation and integers and for the second operation.
- and are considered different, if there exists an integer () such that .
输入格式
There are multiple test cases. The first line of the input contains an integer $T$, indicating the number of test cases. For each test case:The first line contains an integer (), indicating the length of two binary sequences.
The second line contains a string () of length , indicating the first binary sequence.
The third line contains a string () of length , indicating the second binary sequence.
It's guaranteed that the sum of in all test cases will not exceed .
输出格式
For each test case, output an integer denoting the answer.3
1
1
0
2
00
11
5
01010
00111
0
2
6
提示
For the second sample test case, there are two valid operation pairs: $(1, 1, 2, 2)$ and $(2, 2, 1, 1)$.For the third sample test case, there are six valid operation pairs: , , , , and . 标签: P9887|2018|O2优化|ICPC|青岛