HDU 2041 super stair

Source: Internet
Author: User

Problem Description
There is a total of M-level stairs. At the beginning, you are at the first level. If you can only cross the upper or second level at a time, how many steps should you go to the level M?
 


Input
The input data first contains an integer N, indicating the number of test instances, and then N rows of data. Each row contains an integer M (1 <= M <= 40), indicating the level of the stairs.
 


Output
For each test instance, please output the number of different steps
 


Sample Input
2
2
3


Sample Output
1
2

 

 

Import java. io. bufferedInputStream; import java. util. *; public class Main {public static void main (String [] args) {consumer SC = new consumer (new BufferedInputStream (System. in); int k, m, n; k = SC. nextInt (); for (int I = 0; I <k; I ++) {m = SC. nextInt (); n = fun (m); System. out. println (n) ;}} public static int fun (int m) {int sum = 0; int a [] = new int [m]; for (int I = 2, j = 0; I <= m; I ++, j ++) {if (I = 2) {a [j] = 1; sum = a [j];} else if (I = 3) {a [j] = 2; sum = a [j];} else {a [j] = a [J-1] + a [J-2]; sum = a [j];} return sum ;}}

 

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.