Codeforces Global Round 18
F
LEGOndary Grandmaster
Codeforces
2800
原题
← EG →
翻译中…

After getting bored by playing with crayons, you decided to switch to Legos! Today, you're working with a long strip, with height $1$ and length $n$, some positions of which are occupied by $1$ by $1$ Lego pieces.

翻译中…

In one second, you can either remove two adjacent Lego pieces from the strip (if both are present), or add two Lego pieces to adjacent positions (if both are absent). You can only add or remove Lego's at two adjacent positions at the same time, as otherwise your chubby fingers run into precision issues.

翻译中…

You want to know exactly how much time you'll spend playing with Legos. You value efficiency, so given some starting state and some ending state, you'll always spend the least number of seconds to transform the starting state into the ending state. If it's impossible to transform the starting state into the ending state, you just skip it (so you spend $0$ seconds).

翻译中…

The issue is that, for some positions, you don't remember whether there were Legos there or not (in either the starting state, the ending state, or both). Over all pairs of (starting state, ending state) that are consistent with your memory, find the total amount of time it will take to transform the starting state to the ending state. Print this value modulo $1\,000\,000\,007$ ($10^9 + 7$).

翻译中…

Input

翻译中…

The first line contains one integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. Then $t$ cases follow.

翻译中…

The first line of each test case contains one integer $n$ ($2 \leq n \leq 2000$) — the size of the Lego strip.

翻译中…

The second line of each test case contains a string $s$ of length $n$, consisting of the characters 0, 1, and ? — your memory of the starting state:

翻译中…
  • 1 represents a position that definitely has a Lego piece,
  • 0 represents a position that definitely does not have a Lego piece,
  • and ? represents a position that you don't remember.
翻译中…

The third line of each test case contains a string $t$ of length $n$, consisting of the characters 0, 1, and ? — your memory of the ending state. It follows a similar format to the starting state.

翻译中…

It's guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.

翻译中…

Output

翻译中…

For each test case, output a single integer — the answer to the problem modulo $1\,000\,000\,007$ ($10^9 + 7$).

翻译中…

Note

翻译中…

For the first test case, $00$ is the only possible starting state, and $11$ is the only possible ending state. It takes exactly one operation to change $00$ to $11$.

翻译中…

For the second test case, some of the possible starting and ending state pairs are:

翻译中…
  • $(000, 011)$ — takes $1$ operation.
  • $(001, 100)$ — takes $2$ operations.
  • $(010, 000)$ — takes $0$ operations, as it's impossible to achieve the ending state.
翻译中…

样例

Input #1
6
2
00
11
3
???
???
3
??1
0?0
4
??0?
??11
5
?????
0??1?
10
?01??01?1?
??100?1???
Output #1
1
16
1
14
101
1674
InputCopy OutputCopy
题目信息
题号
1615F
时间限制
2 s
内存限制
512 MB
标签
组合数学
动态规划
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。