Breaking walls
Practice
4.3 (6 votes)
Datastructures
Graphs
Algorithms
Depth first search
Problem
76% Success 2144 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code
Bob is assigned a task to collect the maximum stars possible. He has a hammer that can be used to break only one wall!
You are given a grid of size \(N\times M\) that contains $$.$$, $$*$$, $$#$$. Here:
- $$.$$ represents all the points where Bob can move
- $$#$$ represents the walls and hence bob cannot pass through it or be on it
- $$*$$ represents the stars bob needs to collect
Note: If you can reach this cell, you can collect this star.
Bob is allowed to start on any of the non $$#$$ cells and he is free to move up, down, left, or right. But, having the hammer, Bob can break only one wall and move through that broken wall.
Bob wants to collect the maximum possible stars possible. Help Bob by finding the maximum possible stars he can collect.
Input format
- The first line contains two integers $$N$$ and $$M$$.
- Next $$N$$ lines contains $$M$$ characters consisting of $$.$$, $$*$$, $$#$$.
Output format
Print a single line containing a single integer.
Constraints
\(1 \le N, M \le 1000\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
16 votes
Tags:
AlgorithmsApprovedGraphsMediumOpenTrees
Points:30
6 votes
Tags:
AlgorithmsDepth First SearchGraphsMedium
Points:30
8 votes
Tags:
AlgorithmsApprovedCombinatoricsDepth First SearchDynamic ProgrammingGraphsMathMediumReadyRecruit
Editorial