|
|||
Grid GameAlice and Bob both have lots of candies but want more. They decide to play the following turn-based game. They fill an n × n grid M with random integers. Alice begins the game by crossing off an uncrossed row i of the grid. Now it’s Bob turn and he crosses off an uncrossed column j of the grid. At the end of Bob’s turn, Alice takes the number candies in the ith row and jth column of M, call this value M(i, j), from Bob. (If M(i, j) is negative, then Alice gives |M(i, j)| candies to Bob.) The game continues alternating turns from Alice to Bob until the entire board is crossed off. What is the largest amount of candies that Alice can win from Bob (or least amount to lose if she cannot win) if both Alice and Bob play optimally?
Input SpecificationThe first line of the input contains an integer t (1 ≤ t ≤ 20), the number of test cases. Each test case starts with n (1 ≤ n ≤ 8), the size of the grid. Then follow n lines containing n numbers separated by spaces describing M. We call the jth number on ith line M(i, j) (-1000 ≤ M(i, j) ≤ 1000). Output SpecificationFor each test case, print the largest amount of candies that Alice can win from Bob. If she cannot win, print the negative number indicating the minimum number of candies she loses. Sample Input
Output for Sample Input
|
|||
University of Debrecen; Faculty of Informatics; v. 09/30/2024 |