CF1244B Rooms and Staircases
题目描述
有两层房间,每层 $n$ 个,我们用数对 $(a, b)$ 来表示每个房子,其中 $a$ 表示第几层,$b$ 表示从左向右数第几个
对于房子 $(1, i)$ 或 $(2, i)$,都与 $(1, i - 1), (1, i + 1)$ 或 $(2, i - 1), (2, i + 1)$ 相连
而在若干个或个位置中,又有一个双向的梯子,具体来说,若在 $i$ 的位置有一个梯子,则 $(1, i), (2, i)$ 是相连的
求不重复经过同一个房间的情况下,最多能走过多少个房间
输入格式
第一行给出测试数据组数
对于每组测试数据:
第一行给出 $n$,意义如上
第二行给出一个长度为 $n$ 的 $01$ 串,若在 $i$ 位为 $1$,代表在位置 $i$ 有个梯子
输出格式
不重复经过同一个房间的情况下,最多能走过多少个房间
说明/提示
In the first test case Nikolay may start in the first room of the first floor. Then he moves to the second room on the first floor, and then — to the third room on the first floor. Then he uses a staircase to get to the third room on the second floor. Then he goes to the fourth room on the second floor, and then — to the fifth room on the second floor. So, Nikolay visits $ 6 $ rooms.
There are no staircases in the second test case, so Nikolay can only visit all rooms on the same floor (if he starts in the leftmost or in the rightmost room).
In the third test case it is possible to visit all rooms: first floor, first room $ \rightarrow $ second floor, first room $ \rightarrow $ second floor, second room $ \rightarrow $ first floor, second room $ \rightarrow $ first floor, third room $ \rightarrow $ second floor, third room $ \rightarrow $ second floor, fourth room $ \rightarrow $ first floor, fourth room $ \rightarrow $ first floor, fifth room $ \rightarrow $ second floor, fifth room.
In the fourth test case it is also possible to visit all rooms: second floor, third room $ \rightarrow $ second floor, second room $ \rightarrow $ second floor, first room $ \rightarrow $ first floor, first room $ \rightarrow $ first floor, second room $ \rightarrow $ first floor, third room.