Algorithm title: UVA 10651 Pebble Solitaire (BFS + hash Weight (memory search?))

Source: Internet
Author: User
Tags hash

Pebble Solitaire is a interesting game. This is a game where your are given a board with a arrangement of small, cavities all initially one but by a occupied Le each. The aim of the game is to remove as many pebbles as possible from the board. Pebbles disappear from the board as a. A move are possible if there is a straight line of three adjacent cavities, let us call them a, B, and C, with B in the mid Dle, where a is vacant, but B and C contain A pebble. The move constitutes of moving the pebble from C to A, and removing the pebble in bfrom the board. You could continue to make moves until no more moves are possible.

In this problem, we look at the simple variant of the this game, namely a board with twelve cavities located a line. In the beginning of each game, some of the cavities are occupied by pebbles. Your mission is to find a sequence of moves such this as few pebbles as possible are left on the board.

Input

The input begins with a positive integer n on a line of it own. Thereafter n different games follow. Each game consists of one line of input with exactly twelve characters, describing the twelve cavities of the board in Ord Er. Each character is either '-' or ' O ' (the fifteenth character of 中文版 alphabet in lowercase). A '-' (minus) character denotes a empty cavity, whereas a ' o ' character denotes a cavity with a pebble In it. As you'll find in the sample this there may to inputs where no moves is possible.

Output

For each of the "N Games in" input, output the minimum number of pebbles left on the board possible to obtain as a Resul T of moves, on a row of the its own.

Sample input Output for sample input

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.