BCTSP2 - Travelling Salesman Problem 2
A traveler who wants to visit n cities T1, ..., Tn. Comes from one particular city, people who plan to travel
through all other cities, each city exactly once and then passing back the city of origin.
Call C [i] [j] is the cost of going from city Ti to Tj. Look for a satisfactory itinerary of the problem
so that the cost is minimal.
Note: all TSP 2 aims to train for greedy algorithm, this algorithm does not guarantee always found answers optimum,
however for the purpose of practicing the test of TSP 2 were selected for greed also found is the efficient solution.
Input
The first line consists of an integer n (0 <n <= 1000) - the number of cities
The next N lines, the ith row enter n integer C [i] [j] (0 <= j <n, 0 <C [i] [j] <= 10 ^ 9) - is the cost of
going from city Ti to Tj and vice versa
Output
Print the minimum cost can be achieved
Example
Input:
44
0 20 35 42
20 0 34 30
35 34 0 12
42 30 12 0
0 20 35 42
20 0 34 3035 34 0 1242 30 12
Output:
97
Submit solution!
QkNUU1AyIC0gVHJhdmVsbGluZyBTYWxlc21hbiBQcm9ibGVtIDIKQSB0cmF2ZWxlciB3aG8gd2FudHMgdG8gdmlzaXQgbiBjaXRpZXMgVDEsIC4uLiwgVG4uIENvbWVzIGZyb20gb25lIHBhcnRpY3VsYXIgY2l0eSwgcGVvcGxlIHdobyBwbGFuIHRvIHRyYXZlbCAKdGhyb3VnaCBhbGwgb3RoZXIgY2l0aWVzLCBlYWNoIGNpdHkgZXhhY3RseSBvbmNlIGFuZCB0aGVuIHBhc3NpbmcgYmFjayB0aGUgY2l0eSBvZiBvcmlnaW4uCgpDYWxsIEMgW2ldIFtqXSBpcyB0aGUgY29zdCBvZiBnb2luZyBmcm9tIGNpdHkgVGkgdG8gVGouIExvb2sgZm9yIGEgc2F0aXNmYWN0b3J5IGl0aW5lcmFyeSBvZiB0aGUgcHJvYmxlbSAKc28gdGhhdCB0aGUgY29zdCBpcyBtaW5pbWFsLgoKIAoKTm90ZTogYWxsIFRTUCAyIGFpbXMgdG8gdHJhaW4gZm9yIGdyZWVkeSBhbGdvcml0aG0sIHRoaXMgYWxnb3JpdGhtIGRvZXMgbm90IGd1YXJhb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