超级台阶

描述

有一楼梯共m级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第m级,共有多少走法?

注:规定从一级到一级有0种走法。

 
输入
输入数据首先包含一个整数n(1<=n<=100),表示测试实例的个数,然后是n行数据,每行包含一个整数m,(1<=m<=40), 表示楼梯的级数。
输出
对于每个测试实例,请输出不同走法的数量。
样例输入
2
2
3
样例输出
1
2

 1 import java.util.Scanner;
 2 
 3 public class Main {
 4     public static void main(String[] args) {
 5         Scanner scanner=new Scanner(System.in);
 6         int T;
 7         int n;
 8         int flag[]=new int[50];
 9         int i;
10         
11         flag[1]=0;
12         flag[2]=1;
13         flag[3]=2;
14         
15         for(i=4;i<=40;i++)
16             flag[i]=flag[i-2]+flag[i-1];
17         
18         T=scanner.nextInt();
19         while(T!=0){
20             T--;
21             
22             n=scanner.nextInt();
23             System.out.println(flag[n]);
24         }    
25     }
26 }
27             
28             
 
原文地址:https://www.cnblogs.com/zqxLonely/p/4135668.html