A little bee...
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 29643 accepted submission (s): 10944
Problem description a trained bee can only crawl to the adjacent beehive on the right, not reverse crawling. Calculate the number of possible routes for bees to climb from Master A to Master B.
The structure of the beehive is as follows.
The first line of input data is an integer N, indicating the number of test instances, followed by N rows of data, each row contains two integers, A and B (0 <A <B <50 ).
Output for each test instance, please output the number of possible routes for the bee to climb from the master a to the Master B. The output of each instance occupies one line.
Sample Input
21 23 6
Sample output
13
Ideas:
B-A: indicates the number of different beehive rooms;
Suppose: a = 1; B = 2; M = B-A = 1; the bee passes through 1 beehive; Route 1-> 2; that is, M = 1; sum = 1;
A = 1; B = 3; M = B-A = 2; bees pass through two beehive rooms; Route 1-> 2-> 3;That is1-> 3; M = 2 sum = 2
A = 1; B = 4; M = B-A = 3; 3; 3; Route 1-> 2> 4; 1-> 2-> 3-> 4; 1-> 3-> 4;That isM = 3; sum = 3
A = 1; B = 5; M = B-A = 4; bees pass through four beehive rooms; Route 1-> 2-> 4-> 5; 1-> 2-> 4-> 3-> 5; 1-> 2-> 3-> 5; 1-> 3-> 5; 1-> 3-> 4-> 5; that is, M = 5; sum = 5
Conclusion: that is, the Fibonacci series big [1] = 1; big [2] = 2; big [I] = big [I-1] + big [I-2];
Import Java. util. *; import Java. io. *; import Java. math. biginteger; public class main {public static void main (string [] ARGs) {consumer SC = new consumer (New bufferedinputstream (system. in); biginteger big [] = new biginteger [51]; big [1] = biginteger. valueof (1); big [2] = biginteger. valueof (2); For (INT I = 3; I <= 50; I ++) {big [I] = big [I-1]. add (BIG [I-2]);} int K = SC. nextint (); For (INT I = 0; I <K; I ++) {int n = SC. nextint (); int M = SC. nextint (); system. out. println (BIG [math. ABS (n-m)]) ;}}