|
||||||||||
Treasure HuntingTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 2458 Accepted Submission(s): 683 Problem Description Do you like treasure hunting? Today, with one of his friend, iSea is on a venture trip again. As most movie said, they find so many gold hiding in their trip. Now iSea¡¯s clever friend has already got the map of the place they are going to hunt, simplify the map, there are three ground types: ¡ñ '.' means blank ground, they can get through it ¡ñ '#' means block, they can¡¯t get through it ¡ñ '*' means gold hiding under ground, also they can just get through it (but you won¡¯t, right?) What makes iSea very delighted is the friend with him is extraordinary justice, he would not take away things which doesn¡¯t belong to him, so all the treasure belong to iSea oneself! But his friend has a request, he will set up a number of rally points on the map, namely 'A', 'B' ... 'Z', 'a', 'b' ... 'z' (in that order, but may be less than 52), they start in 'A', each time friend reaches to the next rally point in the shortest way, they have to meet here (i.e. iSea reaches there earlier than or same as his friend), then start together, but you can choose different paths. Initially, iSea¡¯s speed is the same with his friend, but to grab treasures, he save one time unit among each part of road, he use the only one unit to get a treasure, after being picked, the treasure¡¯s point change into blank ground. Under the premise of his friend¡¯s rule, how much treasure iSea can get at most? Input There are several test cases in the input. Each test case begin with two integers R, C (2 ¡Ü R, C ¡Ü 100), indicating the row number and the column number. Then R strings follow, each string has C characters (must be ¡®A¡¯ ¨C ¡®Z¡¯ or ¡®a¡¯ ¨C ¡®z¡¯ or ¡®.¡¯ or ¡®#¡¯ or ¡®*¡¯), indicating the type in the coordinate. The input terminates by end of file marker. Output For each test case, output one integer, indicating maximum gold number iSea can get, if they can¡¯t meet at one or more rally points, just output -1. Sample Input
Sample Output
Author iSea @ WHU Source | ||||||||||
|