{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Here, we want to solve path planning for a mobile robot cleaning a rectangular room floor with furniture. \r\u003cbr\u003e\r\u003cbr\u003eConsider the room floor paved with square tiles whose size fits the cleaning robot (1 * 1). There are \u0027clean tiles\u0027 and \u0027dirty tiles\u0027, and the robot can change a \u0027dirty tile\u0027 to a \u0027clean tile\u0027 by visiting the tile. Also there may be some obstacles (furniture) whose size fits a tile in the room. If there is an obstacle on a tile, the robot cannot visit it. The robot moves to an adjacent tile with one move. The tile onto which the robot moves must be one of four tiles (i.e., east, west, north or south) adjacent to the tile where the robot is present. The robot may visit a tile twice or more. \r\u003cbr\u003e\r\u003cbr\u003eYour task is to write a program which computes the minimum number of moves for the robot to change all \u0027dirty tiles\u0027 to \u0027clean tiles\u0027, if ever possible. "}},{"title":"Input","value":{"format":"HTML","content":"The input consists of multiple maps, each representing the size and arrangement of the room. A map is given in the following format. \r\u003cbr\u003e\r\u003cbr\u003ew h\r\u003cbr\u003ec11 c12 c13 ... c1w\r\u003cbr\u003ec21 c22 c23 ... c2w\r\u003cbr\u003e...\r\u003cbr\u003ech1 ch2 ch3 ... chw\r\u003cbr\u003e\r\u003cbr\u003eThe integers w and h are the lengths of the two sides of the floor of the room in terms of widths of floor tiles. w and h are less than or equal to 20. The character cyx represents what is initially on the tile with coordinates (x, y) as follows. \r\u003cbr\u003e\r\u003cbr\u003e\u0027.\u0027 : a clean tile\r\u003cbr\u003e\u0027*\u0027 : a dirty tile \r\u003cbr\u003e\u0027x\u0027 : a piece of furniture (obstacle) \r\u003cbr\u003e\u0027o\u0027 : the robot (initial position)\r\u003cbr\u003e\r\u003cbr\u003eIn the map the number of \u0027dirty tiles\u0027 does not exceed 10. There is only one \u0027robot\u0027. \r\u003cbr\u003e\r\u003cbr\u003eThe end of the input is indicated by a line containing two zeros. "}},{"title":"Output","value":{"format":"HTML","content":"For each map, your program should output a line containing the minimum number of moves. If the map includes \u0027dirty tiles\u0027 which the robot cannot reach, your program should output -1. "}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e7 5\r\n.......\r\n.o...*.\r\n.......\r\n.*...*.\r\n.......\r\n15 13\r\n.......x.......\r\n...o...x....*..\r\n.......x.......\r\n.......x.......\r\n.......x.......\r\n...............\r\nxxxxx.....xxxxx\r\n...............\r\n.......x.......\r\n.......x.......\r\n.......x.......\r\n..*....x....*..\r\n.......x.......\r\n10 10\r\n..........\r\n..o.......\r\n..........\r\n..........\r\n..........\r\n.....xxxxx\r\n.....x....\r\n.....x.*..\r\n.....x....\r\n.....x....\r\n0 0\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e8\r\n49\r\n-1\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}