#P7751. [COCI 2013/2014 #2] PUTNIK
[COCI 2013/2014 #2] PUTNIK
Description
Salesman Sept has a task: to visit cities (numbered from to ), and each city must be visited exactly once.
Among these cities, there is a flight between every pair of cities. Sept values efficiency, so he wants to minimize the total time spent flying. For this, he may change the visiting order of the cities.
However, Sept has a strange requirement for the visiting order:
- There is no requirement for city .
- If he is going to visit city , then all cities with numbers smaller than must be visited either all before visiting city , or all after visiting city .
In other words, for two cities , it is not allowed that city is visited before city while city is visited after city .
Under these restrictions, given the time needed to take flights between every pair of cities, find the minimum total flying time Sept spends.
Input Format
The first line contains an integer , the number of cities.
The next lines each contain integers. Let denote the -th number in the -th line. Then:
- is the time needed to take a flight between cities and .
- If , then .
- .
Output Format
Output one integer in a single line, the minimum total flying time Sept spends.
3
0 5 2
5 0 4
2 4 0
7
4
0 15 7 8
15 0 16 9
7 16 0 12
8 9 12 0
31
Hint
Explanation of Sample 1
The order or is valid.
Note that takes less time, but it does not satisfy Sept's strange requirement.
Explanation of Sample 2
The order or is valid.
Constraints
This problem does not use bundled testdata, and subtasks will not be shown in judging.
- Subtask 1 : .
- Subtask 2 : .
- Subtask 3 : no special restrictions.
For of the data, , .
Source
This problem is translated from COCI2013-2014 CONTEST 2 T4 PUTNIK.
According to the original testdata setup, the full score of this problem is points.
Translated by ChatGPT 5
京公网安备 11011102002149号