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
Deepak : 2016-04-19 23:51:44

silly mistake gave me 2 WAs.nice one to do ;)

Vivek Mangal: 2016-02-21 17:55:37

[spoiler] and accepted

Last edit: 2016-07-29 22:15:55
ngoduchuy64: 2015-12-21 04:34:52

3 attempts still getting WA

Abishek: 2015-09-17 13:46:48

simple problem ..after this try BYTESM2. similar concept .

abhijeet gusain: 2015-02-19 13:14:36

just use desi jugaad ..

sheldon: 2015-01-09 20:50:18

nice ques...finally accepted..:)

S: 2014-12-25 20:37:02

I don't know what is wrong in my code...someone please check it or give me some tricky cases.
[spoiler removed]

Last edit: 2015-08-10 21:04:00
Ruchir Thaman: 2014-10-24 12:26:19

If the initial position contains a blocked box,the answer has to be zero,costed me 2 WA.

Anuva Agarwal: 2014-10-15 19:58:06

Can't believe it turned out to be THIS easy :D

SHIVAM DIXIT: 2014-10-10 14:22:30

good [spoiler removed] for beginners :)

Last edit: 2014-11-12 00:40:37

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