欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1549B.Gregor and the Pawn Game
Gregor and the Pawn Game
There is a chessboard of size by . The square in the -th row from top and -th column from the left is labelled .
Currently, Gregor has some pawns in the -th row. There are also enemy pawns in the -st row. On one turn, Gregor moves one of his pawns. A pawn can move one square up (from to ) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from to either or ) if and only if there is an enemy pawn in that square. The enemy pawn is also removed.
Gregor wants to know what is the maximum number of his pawns that can reach row ?
Note that only Gregor takes turns in this game, and the enemy pawns never move. Also, when Gregor's pawn reaches row , it is stuck and cannot make any further moves.
Input
The first line of the input contains one integer () — the number of test cases. Then test cases follow.
Each test case consists of three lines. The first line contains a single integer () — the size of the chessboard.
The second line consists of a string of binary digits of length , where a in the -th position corresponds to an enemy pawn in the -th cell from the left, and corresponds to an empty cell.
The third line consists of a string of binary digits of length , where a in the -th position corresponds to a Gregor's pawn in the -th cell from the left, and corresponds to an empty cell.
It is guaranteed that the sum of across all test cases is less than .
Output
For each test case, print one integer: the maximum number of Gregor's pawns which can reach the -st row.
Note
In the first example, Gregor can simply advance all of his pawns forward. Thus, the answer is .
In the second example, Gregor can guarantee that all of his pawns reach the enemy row, by following the colored paths as demonstrated in the diagram below. Remember, only Gregor takes turns in this "game"!

In the third example, Gregor's only pawn is stuck behind the enemy pawn, and cannot reach the end.
In the fourth example, Gregor has no pawns, so the answer is clearly .
Samples
4
3
000
111
4
1111
1111
3
010
010
5
11001
00000
3
4
0
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |