39th step Xiao Ming just finished watching the film "39th Step", when he left the cinema, he counted the number of steps in front of the auditorium, which happens to be level 39!__ 39th steps

Source: Internet
Author: User
Tags ming
Package org.bluebridge.topics;
 * * 39th step
 Xiao Ming just finished watching the film "39th Step", when he left the cinema, he counted the number of steps in front of the auditorium, happens to be level 39!
 Standing in front of the steps, he suddenly thought of a question:
 If I could only step 1 or 2 steps each. Take the left foot first, then turn left and right, and the
 last step is to take the right-hand foot, which means you have to go even step.
 So, how many different methods are there when you finish the 39 steps?
 Please use the advantage of the computer to help xiaoming find the answer.
 * */Public

class Number_39steps {public

	static void Main (string[] args) {

		int[][] step = new int[39][ 2];//first Dimension is a 39-storey ladder, the second dimension is left

		/right foot//For the first step, there are 1 ways to reach the left foot, 0 kinds (because the title requires first to step left foot)
		step[0][0] = 1;
		STEP[0][1] = 0;

		For the second ladder, there are 1 ways to get to the left foot, because each step can only reach 1 or 2 steps, the right foot has 1 kinds of
		step[1][0] = 1;
		STEP[1][1] = 1;

		for (int i = 2; i < i++) {
			step[i][1] = step[i-2][0] + step[i-1][0];
			Step[i][0] = step[i-2][1] + step[i-1][1];
		}

		System.out.println (step[38][1]);
	}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.