21840_RecursiveAnts

2022-5-16 18:20| 发布者: Hocassian| 查看: 22| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505892666200-Problem List-采集的数据-后羿采集器.html

Pro.ID

21840

Title

Recursive Ants

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21840

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    In a 2n*2n chess board, some grids is marked visitable, and others are not. Mr. Ant is planning to visit all the visitable grids on the board, and each grid can be visited only once. Mr. Ant start from the left-top side of the board, and he should finish his journey at any grid on the edge of the board. Of course we assume that the start point of Mr. Ant is always visitable.

    In every step, Mr. Ant can move from one grid to the adjacent grid (that is to say he can move up, down, left, right in four directions).

    Mr. Ant's path is defined recursively. That is to say, if Mr. Ant wants to visit a 2k*2k chess board, then we divided the board into four pieces, and each one has a size of 2(k-1)*2(k-1), in every part, Mr. Ant should visit all the grids in the four parts and then move onto another. Of course, we should divided this 2(k-1)*2(k-1) board into four smaller pieces and Mr. Ant's path should be defined in these new four parts.

    输入

    The input-file consists of several test cases. There is a number n ( 1 ≤ n ≤ 7 ) in the beginning of each test case indicating that the width of the chess board: 2n*2n. Each of the next 2n lines contains a string. Character '1' means visitable and '0' means not. Input-file is end with an end-of-file character.

    输出

    Description

    In a 2n*2n chess board, some grids is marked visitable, and others are not. Mr. Ant is planning to visit all the visitable grids on the board, and each grid can be visited only once. Mr. Ant start from the left-top side of the board, and he should finish his journey at any grid on the edge of the board. Of course we assume that the start point of Mr. Ant is always visitable.

    In every step, Mr. Ant can move from one grid to the adjacent grid (that is to say he can move up, down, left, right in four directions).

    Mr. Ant's path is defined recursively. That is to say, if Mr. Ant wants to visit a 2k*2k chess board, then we divided the board into four pieces, and each one has a size of 2(k-1)*2(k-1), in every part, Mr. Ant should visit all the grids in the four parts and then move onto another. Of course, we should divided this 2(k-1)*2(k-1) board into four smaller pieces and Mr. Ant's path should be defined in these new four parts.

    Input

    The input-file consists of several test cases. There is a number n ( 1 ≤ n ≤ 7 ) in the beginning of each test case indicating that the width of the chess board: 2n*2n. Each of the next 2n lines contains a string. Character '1' means visitable and '0' means not. Input-file is end with an end-of-file character.

    Output

    For every case, you only need to output one line. Output "YES" if Mr. Ant can finish his journey as described above, else output "NO".

    Sample Input

    1
    11
    10
    2
    1100
    0110
    0111
    0111
    3
    11001100
    01111100
    01111111
    01111111
    11111111
    11111111
    00001111
    00001111

    Sample Output

    NO
    NO
    YES

    Source

    样例输入

    1
    11
    10
    2
    1100
    0110
    0111
    0111
    3
    11001100
    01111100
    01111111
    01111111
    11111111
    11111111
    00001111
    00001111

    样例输出

    NO
    NO
    YES

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部