Bored Games

0

0 votes
Medium
Problem

There is a 4 x 4 board having coins on each cell. Each coin has a non-zero value written on it. There are two players A and B, who take turns to play a game. In each turn, the player takes coins lying on a straight line on the board (the line is parallel to the sides of the board), such that the line covers no empty cells (all coins are contiguous.) Game ends when board is emptied, and the final score is sum of weights of all coins gathered by the player at the end of the game. A strives to maximise the difference between A’s score and B’s score, while B tries to minimise it. Assuming both play optimally, what is the best score for A if A starts the game?

Input format :

Input consists of a single test case, a 4 by 4 matrix of integers in the range [-10^6, 10^6]. A value of zero indicates an empty cell.

Output format :

Print a single line with that maximum difference between scores of A and B attainable if both play optimally.

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Sample solution = 12 A takes 1,0;1,1;1,2; B takes 0,1;0,2; A takes 3,2; B takes 3,0;3,1; A takes 2,1;2,2; B takes 2,0;

Editor Image

?