ZOJ Problem Set - 1609
When learning mathamatics, sometimes one may come to an theorem which goes like this:
The following statements are equivalent:
For example, let A be an angle between 0 and 360 degrees, the following statements
Proving such a theorem is usually a difficult task, because you have to prove that for any two statements Si and Sj, Si concludes Sj and vise versa. Sometimes, proving Si concludes Sj directly is quite difficult so we may find a Sk and prove that Si concludes Sk and Sk concludes Sj. Now given the difficulty of proving every Si => Sj, you are to calculate the minimal total difficulty to prove that the given statements are equivalent.
The input contains several cases. Each case begins with an integer n (2 <= n <= 6), the number of statements in this case, followed by n lines, each contains n integers.
The jth integer of the ith row represents the difficulty of proving Si => Sj. The ith integer of the ith row is always 0 as it's obvious that Si concludes Si. All the n * n integers are between 0 and 100, inclusively. Input is terminated by EOF.
For each test case, output a line with the minimal difficulty for that case.
Author: PAN, Minghao
Source: ZOJ Monthly, May 2003