#P4553. 80 人环游世界
80 人环游世界
Description
I’m sure many of you have seen Jackie Chan’s “Around the World in 80 Days,” and the intense, thrilling fight scenes must have left a deep impression. Now, there is a group of 80 people who also want to travel around the world.
They plan to split up and visit every country.
Since they are mainly located in the East, they will only move westward. Let the countries from east to west be numbered . If the -th person’s itinerary is , then .
As we all know, China is very beautiful, so many people will pass through China during their trip. We use a positive integer to describe a country’s attractiveness. The larger the value of , the more attractive the country is, and it also means that exactly people will pass through that country.
To save time, they plan to travel by plane. To save money, they want the total airfare to be minimal.
They are leaving tomorrow, but some people bailed at the last minute, and in the end only people will travel around the world. They want to know the minimal total cost. Please compute it.
Input Format
The first line contains two positive integers .
The second line has positive integers, each not greater than , representing .
Then there are lines. The -th of these lines contains integers. The -th number on this line is the airfare from the -th country to the -th country (if this value equals , then there is no direct flight between these two countries).
Output Format
Output the minimal total cost on the first line.
6 3
2 1 3 1 2 1
2 6 8 5 0
8 2 4 1
6 1 0
4 -1
4
27
Hint
- In of the testdata, .
- In of the testdata, .
- In of the testdata, .
- In of the testdata, .
- In of the testdata, , .
It is guaranteed that for all input, the minimal cost is less than .
It is guaranteed that there exists at least one feasible plan.
Jizhong League mock contest problem.
By CQF.
Translated by ChatGPT 5
京公网安备 11011102002149号