Skip to content
balauru edited this page Jul 15, 2012 · 2 revisions

You are playing Nuclear Bomb Man, the poorly designed puzzle sequel to a popular bomb laying game.

In this bomb-laying 2-D puzzle game, you are at the level that introduces the Super Bomb, a bomb with unlimited range in the horizontal and vertical direction. It's weakness, however, is that no Super Bomb can ever be hit by a blast; the end result is so destructive that it causes a Game Over.

On this level, you are scored by the number of Super Bombs you can place, of which you have infinite supply. The map consists of a NxM grid, with a limited number of open spaces to place your Super Bombs. Your task is to select the largest group of Super Bombs such that no two of them are in the same row or in same column.

Input Format

The First line of input contains two space separated integers N and M. Then follow N lines, each containing M space separated boolean values. These NxM entries describe the open spaces on the map. Presence of 1 means that the space is open to place a Super Bomb. 1 <= N, M <= 200.

Output Fomat

Print a single integer which is the maximum number of Super Bombs you can place from the given configuration such that no two Super Bombs belong to same row or same column.

Sample Input

4 5
1 0 1 0 1
0 1 0 1 0
0 0 0 0 0
1 1 0 1 0

Sample Output

3

Explanation

In the given arrangement there are open spaces on the grid. One of multiple valid arrangements: You can place Super Bombs on coordinates (0, 4), (1, 1) and (3, 3). No two of these Super Bombs are in same row or in same column.

Clone this wiki locally