OILCOMP  Oil Company
Irving & Cohen Petroleum Corporation has decided to develop a new oil field in an area. A preliminary survey has been done and they created a detailed grid map of the area which indicates the reserve of oil.
They are now planning to construct mining plants on several grid blocks according this map, but they decided not to place any two plants on adjacent positions to avoid spreading of fire in case of blaze. Two blocks are considered to be adjacent when they have a common edge. You are one of the programmers working for the company and your task is to write a program which calculates the maximum amount of oil they can mine, given the map of the reserve.
Input
The first line of the input specifies N, the number of test cases. Then N test cases follow, each of which looks like the following:
W H r_{1,1} r_{2,1} ... r_{W,1} ... r_{1,H} r_{2,H} ... r_{W,H}
The first line of a test case contains two integers W and H (1 ≤ W, H ≤ 20). They specifies the dimension of the area. The next H lines, each of which contains W integers, represent the map of the area. Each integer rx,y (0 ≤ rx,y < 10000) indicates the oil reserve at the grid block (x, y).
Output
For each test case, output the case number (starting from 1) and the maximum possible amount of mining in a line. Refer to the sample output section about the format.
Example
Input: 2 2 2 2 3 3 5 3 2 4 1 1 2 1 4 Output: Case 1: 7 Case 2: 8
hide comments
jjsuarestra99:
20191214 06:03:10
Can be solved as a Maximum Weighted Independent Set on a bipartite graph, which is the complement of Minimum Weighted Vertex Cover which can be solved as a Max Flow problem. 

Hasan Jaddouh:
20130318 16:39:39
done in polynomial time O((w*h)^3) worstcase :) 
Added by:  Bin Jin 
Date:  20080908 
Time limit:  2.857s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: C99 ERL JSRHINO NODEJS PERL6 VB.NET 
Resource:  JAG wintercamp 08, day2 