#P9887. [ICPC2018 Qingdao R] Flippy Sequence
[ICPC2018 Qingdao R] Flippy Sequence
题目描述
DreamGrid has just found two binary sequences and ( for all ) from his virtual machine! He would like to perform the operation described below exactly twice, so that holds for all 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 , 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.
题目大意
给定两个长度为 的 01 字符串 。你需要求出有多少个 ,使得分别取反 串的区间 和区间 内的字符串后, 和 相等。取反的定义是对于 01 字符串 ,若 则令 ,否则令 。
,。
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: and .
For the third sample test case, there are six valid operation pairs: , , , , and .