#P2289. Counting Optimal Postal Routes
Counting Optimal Postal Routes
Counting Optimal Postal Routes
Little Li works at the post office in city P. Every day his task is to leave the post office, collect mail from all the mailboxes under his jurisdiction, and return to the post office. These mailboxes are arranged in an m × n grid with equal spacing, and the mailbox at the top‐left corner is exactly at the post office door.
Being an eccentric person, Little Li wants to take a different route each day. However, he does not want to walk any extra distance – he will only choose a route of minimum total length. (Note that the route length is measured as the total physical distance walked, and he is allowed to pass by any mailbox more than once.)
Your task is to compute the number of distinct routes he can take which have the minimum possible distance.
It can be shown that the answer is given by the formula:
[ 2^{(m-1)(n-1)} ]
For example, when m = 2 and n = 2, the answer is \(2^{(2-1)(2-1)} = 2\).
inputFormat
The input consists of a single line containing two integers \(m\) and \(n\): the number of rows and columns of the mailbox grid.
outputFormat
Output a single integer which is the number of distinct optimal routes. According to the analysis, the answer is given by \(2^{(m-1)(n-1)}\).
sample
1 1
1