10218_LongNightofMuseums

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

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

Pro.ID

10218

Title

Long Night of Museums

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    The city of Vienna is called the "City of Culture" because (among other things) there are more than 100 museums in the city. As a consequence, it is very difficult (and very expensive) to visit all of them no matter how long you stay in the city. Fortunately, there is a special night, called the "Long Night of Museums", when you can visit many museums with just one ticket, from 6:00 pm to 1:00 am of the next day.

    Nevertheless, it is impossible to visit every museum of the city for two main reasons. First, some museums in Vienna don't get involved into this event because they close at 5:00 pm. Second, there is not enough time in 7 hours to go to every museum, watch ALL their insides (otherwise, it would be a waste of time), and then go to the others.

    Given the number of museums participating in the Long Night of Museums, the time needed to watch the insides of each museum, and the time that it will take to get from each museum to the others, you have to find the best tour to visit as many museums as you can during the Long Night of Museums.

    输入

    The input contains several test cases. The first line of a test case contains one integer N, which indicates the number of museums participating in the event (1 ≤ N ≤ 20). Each museum has a unique identification number ranging from 1 to N. The second line of a test case contains N integers indicating the time, in minutes, needed to visit each museum, from 1 to N. Then there are N lines describing the times to go from one museum to every other. The i-th line contains N integers Mk (1 ≤ kN) representing the time, in minutes, to go from museum i to museum k. You may assume that the i-th integer in the i-th line is equal to zero. The end of input is indicated by N = 0

    输出

    Description

    The city of Vienna is called the "City of Culture" because (among other things) there are more than 100 museums in the city. As a consequence, it is very difficult (and very expensive) to visit all of them no matter how long you stay in the city. Fortunately, there is a special night, called the "Long Night of Museums", when you can visit many museums with just one ticket, from 6:00 pm to 1:00 am of the next day.

    Nevertheless, it is impossible to visit every museum of the city for two main reasons. First, some museums in Vienna don't get involved into this event because they close at 5:00 pm. Second, there is not enough time in 7 hours to go to every museum, watch ALL their insides (otherwise, it would be a waste of time), and then go to the others.

    Given the number of museums participating in the Long Night of Museums, the time needed to watch the insides of each museum, and the time that it will take to get from each museum to the others, you have to find the best tour to visit as many museums as you can during the Long Night of Museums.

    Input

    The input contains several test cases. The first line of a test case contains one integer N, which indicates the number of museums participating in the event (1 ≤ N ≤ 20). Each museum has a unique identification number ranging from 1 to N. The second line of a test case contains N integers indicating the time, in minutes, needed to visit each museum, from 1 to N. Then there are N lines describing the times to go from one museum to every other. The i-th line contains N integers Mk (1 ≤ kN) representing the time, in minutes, to go from museum i to museum k. You may assume that the i-th integer in the i-th line is equal to zero. The end of input is indicated by N = 0

    Output

    For each test case in the input, your program must produce one line containing the maximum number of museums that can be visited during the Long Night of Museums.

    Sample Input

    2
    500 500
    0 120
    200 0
    2
    220 220
    0 30
    20 0
    2
    150 150
    0 120
    200 0
    0

    Sample Output

    0
    1
    2

    Hint

    You must find to try your best to visit as many DIFFERENT museums as you can during the Long Night of Museums.

    Source

    样例输入

    2
    500 500
    0 120
    200 0
    2
    220 220
    0 30
    20 0
    2
    150 150
    0 120
    200 0
    0

    样例输出

    0
    1
    2

    提示

    You must find to try your best to visit as many DIFFERENT museums as you can during the Long Night of Museums.


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部