Ultraviolet A the Sultan's successors

Source: Internet
Author: User

The questions are as follows:

The Sultan's successors

The Sultan of Nubia has no children, so she has decided that thecountry will be split into upKSeparate Parts on her death andeach part will be inherited by whoever performs best at some test. itis possible for any individual to inherit more than one or indeed allof the portions. to ensure that only highly intelligent peopleeventually become her successors, the Sultan has devised an ingenioustest. in a large hall filled with the splash of fountains and thedelicate scent of incense have been placedKChessboards. eachchessboard has numbers in the range 1 to 99 written on each square andis supplied with 8 jewelled chess queens. the task facing eachpotential successor is to place the 8 queens on the chess board insuch a way that no Queen threatens another one, and so that thenumbers on the squares thus selected sum to a number at least as highas one already chosen by the Sultan. (For those unfamiliar with therules of chess, this implies that each row and column of the boardcontains exactly one queen, and each diagonal contains no more thanone .)

Write a program that will read in the number and details of thechessboards and determine the highest scores possible for each boardunder these conditions. (You know that the Sultan is both a good ChessPlayer and a good mathematician and you suspect that her score is thebest attainable .)

Input

Input will consistK(The number of boards), on a line by itself, followedKSets of 64 numbers, each set consisting of eight linesof eight numbers. Each number will be a positive integer less than100. there will never be more than 20 boards.

Output

Output will consistKNumbers consisting of yourKScores, eachscore on a line by itself and right justified in a field 5 characterswide.

Sample Input
1 1  2  3  4  5  6  7  8 9 10 11 12 13 14 15 1617 18 19 20 21 22 23 2425 26 27 28 29 30 31 3233 34 35 36 37 38 39 4041 42 43 44 45 46 47 4848 50 51 52 53 54 55 5657 58 59 60 61 62 63 64
Sample output
  260

The classic eight queens question is detailed in the white book. Here, we only need to calculate the maximum value of the sum of the number of cells to be located, and maintain the maximum value in one case.

The AC code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.