1795.
Jumping Yoshi
时间限制 5000 ms
内存限制 128 MB
oshi is a frog. He lives in the ZOO under a log which was specially transported there from
a distant equatorial rainforest. The log is big and wet and attracts the flies and that is what
makes Yoshi satisfied.
There is also a line of pebbles which runs through the wetland in front of the log. There are
various dark spots on the pebbles and sometimes Yoshi likes to look at them and dream that
they are not just spots but some really big flies instead.
Yesterday, Yoshi’s friend camel Addawser came to see him and suggested to play a game.
“Do you see those spots on the pebbles?” asked Addawser. “I challenge you to start on the
leftmost pebble and then do some jumps from a pebble to another pebble but with some restrictions. You can jump from a pebble to another one only if the sum of numbers of spots on both
pebbles is equal to the distance between the pebbles. And you have to get to as distant pebble
as possible.”
“All right, but you know that I can count at most to twenty three and no more,” hesitated
Yoshi.
“No problem, I will help you with the bigger numbers,” said Addawser.
“Then, it’s easy,” said Yoshi, positioning himself on the first pebble and looking inquisitively
over the rest of the line. “Although, one might not be quite so sure, after all,” he added after a
while.
You are given the sequence of numbers of dark spots on the pebbles in the line. You are asked
to find the most distant pebble which can be reached by a sequence of jumps. The first jump
starts at the first pebble in the line and a jump between two pebbles is possible if and only if
the sum of numbers of spots on both pebbles is equal to the distance between them. You may
suppose that the line of pebbles is straight and that the distance between each two neighboring
pebbles is exactly one frog distance unit.
输入数据
输出数据
For each test case, print a single line with one integer denoting the distance of the pebble which
can be reached by successive jumps according to the given rules and which is the most distant
from the first pebble.
样例输入
复制
7
2 1 0 1 2 3 3
11
7 6 1 4 1 2 1 4 1 4 5
0
\n
· · · · · · \n
\n
· · · · · · · · · · \n
\n