306728: CF1244B. Rooms and Staircases
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
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$ 有个梯子 ### 输出格式 不重复经过同一个房间的情况下,最多能走过多少个房间题目描述
Nikolay lives in a two-storied house. There are $ n $ rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number is an integer between $ 1 $ and $ n $ ). If Nikolay is currently in some room, he can move to any of the neighbouring rooms (if they exist). Rooms with numbers $ i $ and $ i+1 $ on each floor are neighbouring, for all $ 1 \leq i \leq n - 1 $ . There may also be staircases that connect two rooms from different floors having the same numbers. If there is a staircase connecting the room $ x $ on the first floor and the room $ x $ on the second floor, then Nikolay can use it to move from one room to another. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1244B/c3053f6602a9b90cafab0dc252fe4e75c11e365b.png) The picture illustrates a house with $ n = 4 $ . There is a staircase between the room $ 2 $ on the first floor and the room $ 2 $ on the second floor, and another staircase between the room $ 4 $ on the first floor and the room $ 4 $ on the second floor. The arrows denote possible directions in which Nikolay can move. The picture corresponds to the string "0101" in the input. Nikolay wants to move through some rooms in his house. To do this, he firstly chooses any room where he starts. Then Nikolay moves between rooms according to the aforementioned rules. Nikolay never visits the same room twice (he won't enter a room where he has already been). Calculate the maximum number of rooms Nikolay can visit during his tour, if: - he can start in any room on any floor of his choice, - and he won't visit the same room twice.输入输出格式
输入格式
The first line of the input contains one integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases in the input. Then test cases follow. Each test case consists of two lines. The first line contains one integer $ n $ $ (1 \le n \le 1\,000) $ — the number of rooms on each floor. The second line contains one string consisting of $ n $ characters, each character is either a '0' or a '1'. If the $ i $ -th character is a '1', then there is a staircase between the room $ i $ on the first floor and the room $ i $ on the second floor. If the $ i $ -th character is a '0', then there is no staircase between the room $ i $ on the first floor and the room $ i $ on the second floor. In hacks it is allowed to use only one test case in the input, so $ t = 1 $ should be satisfied.
输出格式
For each test case print one integer — the maximum number of rooms Nikolay can visit during his tour, if he can start in any room on any floor, and he won't visit the same room twice.
输入输出样例
输入样例 #1
4
5
00100
8
00000000
5
11111
3
110
输出样例 #1
6
8
10
6