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:


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

hide comments
2015-12-21 04:34:52
3 attempts still getting WA
2015-09-17 13:46:48 Abishek
simple problem ..after this try BYTESM2. similar concept .
2015-02-19 13:14:36 abhijeet gusain
just use desi jugaad ..
2015-01-09 20:50:18 sheldon
nice ques...finally accepted..:)
2014-12-25 20:37:02 S
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
2014-10-24 12:26:19 Ruchir Thaman
If the initial position contains a blocked box,the answer has to be zero,costed me 2 WA.
2014-10-15 19:58:06 Anuva Agarwal
Can't believe it turned out to be THIS easy :D
2014-10-10 14:22:30 SHIVAM DIXIT
good [spoiler removed] for beginners :)

Last edit: 2014-11-12 00:40:37
2014-10-10 03:17:51 Andres Mauricio Rondon Patiño
[spoiler removed] works

Last edit: 2014-11-12 00:40:55
2014-09-07 02:31:48 Girish Rathi
well bfs gives tle use [spoiler removed]

Last edit: 2014-11-12 00:41:06
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.