UVa 10944 - Nuts for nuts..

10944 - Nuts for nuts..

 * http://acm.uva.es/p/v109/10944.html

Summary
This is actually an easier version of UVa 10937 - Blackbeard the Pirate, so with minor modifications, you can solve both problems.

The difference is that this problem requires Dynamic Programming due to having more data points, but a Breadth-First Search is not needed due to having no obstacles.

Explanation
This is pretty much the same as UVa 10937 - Blackbeard the Pirate, so you can confer that problem.

Input
5 5 L.... ..... 5 5 L.... .....

Output
8 8