回分類題庫
d217: CP2 Lab Exercise: Mr. U Lost in the Wood
出處:

Difficulity : N/A
Accepted : 52 Times | Submit :114 Times | Clicks : 1523
Accepted : 34 Users | Submit : 37 Users | Accepted rate : 92%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2011-03-30 15:26

Content :

"Mr. U" lost in the forest of Pandora. He can only move 4 Directions (Forward, backward, left and right.) in this forest.

Luckily, Mr. U is a New Type, he can feel the planar map of this forest. Please calculate the total number of paths for Mr. U to help him out of the forest.

Remember, Mr. U is a New Type, he will not walk to the cell which he has already been.

Notice:
You have to use dynamic memory allocation for the forest.
You have to write recursive function to find all the path.

Input :

The input contains several sets of data, for each data, the first line is two integers W and H which indicate the width and height of the forest.

The following H lines describe the forest, each line contains W integers.
0, empty cell which Mr. U can walk.
1, forest cell, Mr. U cannot pass.
2, Mr. U's current position, only appear once in each forest.
3, Mr. U's destination, only appear once in each forest.

Output :

For each data output a line of an integer: the number of path to leave this forest.

Sample Input :

11 4
1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 1 0 0 0 1 0 3
1 0 1 0 0 0 1 0 0 0 1
1 2 1 1 1 1 1 1 1 1 1
14 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 1 0 0 0 0 1 0 0 0 3
1 0 1 0 0 0 1 1 0 0 0 1 1 1
1 0 1 1 1 0 0 0 0 1 1 1 1 1
1 2 1 1 1 1 1 1 1 1 1 1 1 1

Sample Output :

1
2

Hint :


  

Author :


  Solve it!   Status Forum (0)

C++
C
JAVA
55975. johnny (6 ms , 226KB)
55934. ag100 (2 ms , 244KB)
31075. ayakamuxin (4 ms , 274KB)
30816. nothinglo (4 ms , 270KB)
30814. nothinglo (4 ms , 276KB)
31470. cp99703023 (6 ms , 270KB)
57249. nwgs524513cja (136 ms , 176KB)

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡