F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Klotski

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 310    Accepted Submission(s): 23


Problem Description
Klotski game is coming again!



Klotski (from Polish klocki¡ªwooden blocks) is a sliding block puzzle. Sometimes it only refers to the block arrangement in the right-hand-side diagram, where the largest block (in red) must be moved to the bottom middle location (marked in blue). In a more global sense, Klotski refers to a whole group of similar sliding-block puzzles where the aim is to move a specific block to some predefined location.
From Wikipedia.org

But today, I will re-define the game for you.
The board is a n¡Ám grid. There are some blocks on it. A block covers one or more cells of the grid. These blocks are 4-connected. There are also some empty cells on the board. Every step you can move only one block up or down or to the left or to the right , and two blocks can never overlap.
Here the problem comes: giving you two layouts of board, calculate the least step(s) that needed to move blocks so that the board can be transferred from one layout to another.
 

Input
There are several test cases.
For each test, the first line has three integers n,m and k, indicating that the board is n¡Ám and there are k blocks on it. ( 0< n,m<=20, 0<=k<=10).
The following n lines describe the starting layout. Every line has m characters representing m cells. '.' represents an empty cell and ¡®0¡¯~¡¯9¡¯ indicates a cell covered by a block. The none-empty cells which represented by the same characters are all covered by a same block and one block can only cover cells represented by the same characters.
The next n lines describe the ending layout.
Input ends with n = 0 ,m= 0, and k=0.
 

Output
For each test case you should output a line with an integer indicating the least step(s) needed to transform the starting layout into the ending layout.
 

Sample Input
5 4 10 48.. 6200 6200 7311 7359 7632 7632 4811 .005 .009 0 0 0
 

Sample Output
46
 

Hint

About seventy percent of the test cases are of n<=10 and m<=10. There are exactly 10 test cases.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-02 05:09:03, Gzip enabled