UVa 10944 - Nuts for nuts..

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.

Solutions

 * Code All the Problems

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

Output
8 8