MAXWOODS - MAXIMUM WOOD CUTTER
The image explains it all. You initially step at 0,0 facing right. At each step you can move according to the conditions specified in the image. You cannot step into the blocked boxes (in blue). Find the maximum number of trees you can cut.
The first line consists of an integer t, the number of test cases. For each test case the first line consists of two integers m and n, the number of rows and columns. Then follows the description of the matrix M.
M[i][j]=’T’ if the region has a tree.
M[i][j]=’#’ if the region is blocked.
M[i][j]=’0’ (zero) otherwise.
For each test case find the maximum trees that you can cut.
4 5 5 0TTTT T#T#0 #TT#T T00T0 T0#T0 1 1 T 3 3 T#T TTT T#T 1 1 #
8 1 3 0
Solution for test case #1:
ac in 1go
IMHO, I believe if you're handling the starting index having '#' separately, you aren't writing code the way it should be.Last edit: 2019-12-07 19:17:14
NICE [spoiler] problem with [spoiler] state
[spoiler] avoid TLE
Good question of [spoiler] for the beginner easy top-down code :-)
[spoiler] did the job ;)
ac in 1 go :)
easy [spoiler] !!Last edit: 2017-08-02 13:11:04