UVA_10334
This question can be guessed as a series of fibonacci columns.
If you want to prove it, let's take a look at how the light with the number of refraction n is made up, in fact, they are formed by drawing a Ray at the intersection of the final shot light with the number of refraction N-1 and the three crosslines in reverse direction.
Therefore, we can know that the number of final points between the emitted light and the horizontal line in all optical paths with the refraction number N-1 is the total number of optical paths with the refraction number n.
The intersection point can be divided into two types by the nature of the intersection point. We may use x to represent the intersection points formed by the light and the middle horizontal line, and y to represent the intersection points formed by the rays and the horizontal lines on both sides. It is not difficult to find that a class y intersection can be formed when the reverse light is injected at each class x intersection, A Class x intersection and a class y intersection can be formed when a reverse Ray is drawn at each class y intersection. When the number of refraction times is n, it is not difficult to write a recursive formula for the number of class x intersections and the number of class y intersections, x (n) = y (n-1), y (n) = x (n-1) + y (n-1), we add the two formulas to obtain x (n) + y (n) = x (n-1) + y (n-1) + y (n-1) = x (n-1) + y (n-1) + x (n-2) + y (n-2), so f (n) = x (n) + y (n), we can get f (n) = f (n-1) + f (n-2 ).
We have also explained the relationship between the number of X-ray points and the number of X-ray points. Since the number of X-ray points is a Fibonacci number, the number of Optical Paths is a Fibonacci number.
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
BigInteger[] f = new BigInteger[1010];
f[0] = new BigInteger("1");
f[1] = new BigInteger("2");
for(int i = 2; i <= 1000; i ++)
f[i] = f[i - 1].add(f[i - 2]);
while(cin.hasNext())
{
int N = cin.nextInt();
System.out.println(f[N]);
}
}
}