MAXWOODS - MAXIMUM WOOD CUTTER


Problem Statement:


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.

Input:

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.

Output:

 

For each test case find the maximum trees that you can cut.

 

Input Constraints:

1<=t<=10

1<=m,n<=200

 

Example:

Sample Input:

4
5 5
0TTTT
T#T#0
#TT#T
T00T0
T0#T0
1 1
T
3 3
T#T
TTT
T#T
1 1
#

Sample Output:

8
1
3
0

Solution for test case #1:


hide comments
dkkv0000: 2020-01-25 10:50:08

ac in 1go

sandeepd: 2019-12-07 19:16:35

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
scolar_fuad: 2019-09-04 05:37:24

NICE [spoiler] problem with [spoiler] state
....I recommend it for beginner

Last edit: 2019-09-30 14:35:35
sajalagrawal14: 2019-06-25 21:28:13

nice question

cenation007: 2019-06-22 19:59:06

[spoiler] avoid TLE
AC in one go :)

Last edit: 2019-09-30 14:50:50
navin_chandra: 2019-05-22 20:24:59

Good question of [spoiler] for the beginner easy top-down code :-)

Last edit: 2019-09-30 14:51:00
gd251098: 2018-02-09 12:57:30

[spoiler] did the job ;)

mastik5h_1998: 2017-09-22 03:08:38

easy top-down

kartiks22: 2017-08-05 09:51:25

ac in 1 go :)

anurag44: 2017-06-16 23:13:31

easy [spoiler] !!

Last edit: 2017-08-02 13:11:04

Added by:cegprakash
Date:2012-10-14
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 GOSU
Resource:Inspired from http://codeforces.com/problemset/problem/115/B