TSP.旅行商问题

传统题 时间 3000 ms 内存 256 MiB 8 尝试 18 已通过 6 标签

旅行商问题

Problem Description

There are nn cities numbered from 11 to nn. For every two distinct cities i,ji,j, there is a directed road from ii to jj with cost ci,jc_{i,j}.

A travelling salesman starts in city 11. He must visit every city exactly once and finally return to city 11.

Note that ci,jc_{i,j} and cj,ic_{j,i} are not necessarily equal.

Find the minimum total cost of such a trip.

Input Format

The first line contains one integer nn, the number of cities.

The following nn lines each contain nn integers. The jj-th integer on the ii-th line is ci,jc_{i,j}, the cost of the directed road from city ii to city jj.

It is guaranteed that ci,i=0c_{i,i}=0, and 1ci,j1091\le c_{i,j}\le10^9 for iji\ne j.

Output Format

Print one integer, the minimum total cost.

Samples

Sample 1

Input:

4
0 10 15 20
5 0 9 10
6 13 0 12
8 8 9 0

Output:

35

Constraints

2n182\le n\le18

在线编程 IDE

建议全屏模式获得最佳体验