21982_SpecialFis

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

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

Pro.ID

21982

Title

Special Fish

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    There is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It's hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of some other fish who is believed to be female by it.

    A fish will spawn after it has been attacked. Each fish can attack one other fish and can only be attacked once. No matter a fish is attacked or not, it can still try to attack another fish which is believed to be female by it.

    There is a value we assigned to each fish and the spawns that two fish spawned also have a value which can be calculated by XOR operator through the value of its parents.

    We want to know the maximum possibility of the sum of the spawns.

    输入

    The input consists of multiply test cases. The first line of each test case contains an integer n ( 0 < n ≤ 100 ), which is the number of the fish. The next line consists of n integers, indicating the value ( 0 < value ≤ 100 ) of each fish. The next n lines, each line contains n integers, represent a 01 matrix. The i-th fish believes the j-th fish is female if and only if the value in row i and column j if 1.

    The last test case is followed by a zero, which means the end of the input.

    输出

    Description

    There is a kind of special fish in the East Lake where is closed to campus of Wuhan University. It's hard to say which gender of those fish are, because every fish believes itself as a male, and it may attack one of some other fish who is believed to be female by it.

    A fish will spawn after it has been attacked. Each fish can attack one other fish and can only be attacked once. No matter a fish is attacked or not, it can still try to attack another fish which is believed to be female by it.

    There is a value we assigned to each fish and the spawns that two fish spawned also have a value which can be calculated by XOR operator through the value of its parents.

    We want to know the maximum possibility of the sum of the spawns.

    Input

    The input consists of multiply test cases. The first line of each test case contains an integer n ( 0 < n ≤ 100 ), which is the number of the fish. The next line consists of n integers, indicating the value ( 0 < value ≤ 100 ) of each fish. The next n lines, each line contains n integers, represent a 01 matrix. The i-th fish believes the j-th fish is female if and only if the value in row i and column j if 1.

    The last test case is followed by a zero, which means the end of the input.

    Output

    Output the value for each test in a single line.

    Sample Input

    3
    1 2 3
    011
    101
    110
    0

    Sample Output

    6

    Source

    样例输入

    3
    1 2 3
    011
    101
    110
    0

    样例输出

    6

    提示

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部