Monsters in Grid
Practice
3.8 (13 votes)
Basic programming
Bit manipulation
Medium
Problem
30% Success 1508 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a grid of size NxM , where some of the cells have monsters in them. You have N+M lasers , one at each row and one at each column. You can fire any laser at most once. Assume that these lasers move in a straight line without being blocked by anything. Each monster has a health of 2. In one laser strike, a monster's health is reduced by 1. If monster's health become 0, it dies. You have to find the maximum number of monsters that can be killed if you can fire at most K lasers.

Input:
First line contains 3 space separated integers, N, M and K.
Next N lines contains M space separated integers.

Output
Output a single integer denoting the answer.

Constraints
1 <= N, M <= 20
1 <= K <= N + M
Grid values are 0 (empty cell) and 1 (monster).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
16 votes
Tags:
Math BasicBitmaskBasic ProgrammingBit manipulationBasics of Bit ManipulationBit ManipulationMath
Points:30
14 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationMediummedium
Points:30
9 votes
Tags:
Bit ManipulationBasic ProgrammingBit manipulationAlgorithmsObservationBasics of Bit ManipulationMathematics