#P6183. [USACO10MAR] The Rock Game S

    ID: 5164 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 3 上传者: 标签>2010USACOSpecial Judge深度优先搜索,DFS

[USACO10MAR] The Rock Game S

Description

Before the cows go home to rest and have fun, Farmer John wants them to get some mental exercise by playing a game.

The game board consists of nn identical holes, and all holes are initially empty. A cow may either cover an empty hole with a rock, or uncover a hole that was previously covered. A game state is defined by which holes are covered by rocks.

The goal of the game is for the cow to reach every possible game state exactly once, and finally return to the initial state.

Here is an example from one of their games (empty holes are shown as O, and holes covered by rocks are shown as X):

Time Hole 1 Hole 2 Hole 3 Description
00 O O O At the beginning, all holes are empty
11 X Cover hole 3
22 X Cover hole 1
33 O Uncover hole 3
44 X Cover hole 2
55 O Uncover hole 1
66 X Cover hole 3
77 X Cover hole 1

Now the cows are stuck and cannot continue. They must uncover a hole, but no matter which hole they uncover, they will reach a state they have already visited. For example, if they remove the rock from the second hole, they will reach the state they already visited at time 22 (X O X).

Below is a valid solution for 3 holes:

Time Hole 1 Hole 2 Hole 3 Description
00 O O O At the beginning, all holes are empty
11 X Cover hole 2
22 X Cover hole 3
33 O Uncover hole 2
44 X Cover hole 1
55 X Cover hole 2
66 O Uncover hole 3
77 O Uncover hole 2
88 O Uncover hole 1 and return to the original state

Now the cows are tired of this game, and they want you to help.

Given nn, find a valid sequence of states for the game. If there are multiple solutions, output any one of them.

Input Format

Only one line with an integer nn.

Output Format

Print a total of 2n+12^n+1 lines. Each line contains a string of length nn consisting only of characters O and X. The ii-th character of the string indicates whether hole ii is covered or not in that state. The first and last lines must both be all O.

3
OOO
OXO
OXX
OOX
XOX
XXX
XXO
XOO
OOO

Hint

Explanation for Sample 1

See the problem description.

Constraints

For 100%100\% of the testdata, 1n151\le n\le15.

Translated by ChatGPT 5