← 返回 google 的题目列表Count All Paths Between Two Digits in 3x3 Grid (with/without Diagonals)
类型:online_judge
google
Given a 3x3 grid where each cell contains a digit from 1 to 9. Given two different digits a and b (a!=b), find all paths from digit a to digit b. All four directions (up, down, left, right) are allowed, with a and b being in the range 1 to 9.
Requirements:
If only the shortest path is needed, how would you handle it?
How would you allow diagonal moves in the path?
Input Format For requirement 1: Two integers a and b. For requirement 2: Two integers a and b, allowing diagonal movement.
Output Format The number of all found paths.
Example
Input: a = 1, b = 9
Output: x possible paths
Input: a = 1, b = 9 (diagonal allowed)
Output: y possible paths
Example
Input
1 9