1821 - I2P(I)2019_Hu_hw6 Scoreboard

Time

2019/11/04 21:00:00 2019/11/11 18:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11196 Eight Queen
12473 An Interesting Pattern

11196 - Eight Queen   

Description

Each chessboard has numbers in the range 1 to 100 written on each square and is supplied with 8 chess queens. The task is to place the 8 queens on the chess board in such a way that no queen threatens another one, and so that the sum of the numbers on the squares selected is the maximum . (For those unfamiliar with the rules of chess, this implies that each row and column of the board contains exactly one queen, and each diagonal contains no more than one queen.)

Write a program that will read in the number and details of the chessboards and determine the highest scores possible for each board under these conditions.

Input

Input will consist of K (the number of boards), on a line by itself, followed by K sets of 64 numbers, each set consisting of eight lines of eight numbers. Each number will be a non-negative integer less than 100. Each case is separated by a blank line. There will never be more than 20 boards.

Output

The outputs of all test cases should be printed in order. For each test case a line, print the highest score.

Sample Input  Download

Sample Output  Download

Tags




Discuss




12473 - An Interesting Pattern   

Description

You have found an interesting pattern:

0, 1, 3, 2, 6, 7, 5, 4

This, written in binary, is

000, 001, 011, 010, 110, 111, 101, 100

What's so fascinating about this pattern is that adjacent binary forms (and the tail with the head) differ by exactly one bit.

Let's denote such a pattern array with length 2^n (n a positive integer) that starts from 0 as P(n).

You found out that P(n) may be constructed as the following:

If n = 1, then P(n) = [0, 1]

Otherwise, P(n) = P(n - 1) + h(n, reverse(P(n - 1))),

where reverse(a) is a function that reverses the order of the array a,

and h(n, a) is a function that sets the n'th lowest bit of each element in a.

For example, you could construct P(3) by the following:

P(2) = [00, 01, 11, 10]

reverse(P(2)) = [10, 11, 01, 00]

h(3, reverse(P(2))) = [110, 111, 101, 100]

P(3) = P(2) + h(3, reverse(P(2))) = [00, 01, 11, 10] + [110, 111, 101, 100]

= [00, 01, 11, 10, 110, 111, 101, 100]

= [0, 1, 3, 2, 6, 7, 5, 4]

Now, write a program that constructs P(n).

Input

An integer n (0 < n <= 18) followed by a newline character.

Output

P(n), each element separated by a space (but no space at the end), and a trailing newline character.

Sample Input  Download

Sample Output  Download

Tags




Discuss