#P5187. KABOOM
KABOOM
KABOOM
This problem is translated from COCI 2010.02 task T5 KABOOM.
Luka finds in his laboratory a strange tape that is divided into $N$ segments numbered from $1$ to $N$ (from left to right). The tape has negligible thickness and may only be folded at the junctions between two consecutive segments (i.e. between segments $i$ and $i+1$) and the only allowed folding angle is $180^\circ$.
The tape has two sides. One side is fully coated with extremely sticky glue. The other side is only partially coated – only the first $A$ segments and the last $B$ segments are sticky on that side.
Luka wishes to fold the tape completely (i.e. performing exactly $N-1$ folds, each fold folding one end onto the rest) so that it can be unfolded later to restore the scene. However, if in the final stack two sticky surfaces come into contact, the layers will stick together and Luka will not be able to separate them. (Note that Luka’s hand will not stick to the tape.)
Assume that initially the tape is laid out such that the non‐fully‐sticky side (the one with glue on only segments $1\ldots A$ and $N-B+1\ldots N$) is facing up, while the fully sticky side is facing down. When a fold is performed the folded part is flipped. Thus after a fold a segment may appear with one of two orientations. We denote the orientation of a segment by a bit: state 0
means the segment is not flipped (so its top is the partially sticky side and its bottom is fully sticky), and state 1
means that the segment is flipped (so its top is fully sticky and its bottom is the partially sticky side).
More precisely, for a segment with index i in state s
:
- If
s = 0
: the top is sticky if and only if
$$ i \le A \text{ or } i > N - B, $$ and the bottom is always sticky. - If
s = 1
: the top is always sticky, and the bottom is sticky if and only if
$$ i \le A \text{ or } i > N - B. $$
The complete folding is performed in exactly $N-1$ steps. At each step a new segment is added by folding either the left end or the right end onto the rest. The process is as follows:
- Start with a configuration consisting of a single segment:
[(1, 0)]
(segment 1 with state 0). - For each new segment i from 2 to $N$, you choose one of two operations based on a fold instruction:
- If the instruction is
R
(fold from the right), then append segment i with state0
to the right. That is,config = config + [(i, 0)]
. - If the instruction is
L
(fold from the left), then fold the entire current configuration: create a new list by putting segment i with state1
on top, followed by the reversal of the current configuration with each segment’s state flipped (i.e. replaced by1 - state
). Formally, if the current configuration isconfig
, then the new configuration becomes[(i, 1)] + reverse(flip(config))
.
- If the instruction is
- After performing all $N-1$ folds, a stack of $N$ segments (from top to bottom) is obtained.
In the final stack, for every interface between two consecutive segments (say, an upper segment and the one immediately below it), let the upper segment's bottom surface and the lower segment's top surface come into contact. For the folding to be acceptable, at every interface it is not the case that both contacting surfaces are sticky.
Your task is to compute the number of complete folding sequences (each sequence is a string of length $N-1$ over the alphabet {L
, R
}) that result in a final configuration where no interface has two sticky surfaces touching. Since the answer can be very large, output it modulo $10301$.
Note: The time limit is very strict.
inputFormat
The input consists of a single line containing three integers separated by spaces: N A B
.
- N ($1 \le N \le 20$) – the number of segments in the tape.
- A ($0 \le A \le N$) – the number of segments from the beginning that are sticky on the non‐fully sticky side.
- B ($0 \le B \le N$) – the number of segments from the end that are sticky on the non‐fully sticky side.
outputFormat
Output a single integer – the number of valid folding sequences modulo 10301
.
sample
2 0 0
2