zoukankan      html  css  js  c++  java
  • 杭电 2041 超级楼梯

    Description

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

    Input

    输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
     

    Output

    对于每个测试实例,请输出不同走法的数量
     

    Sample Input

    2
    2
    3
     

    Sample Output

    1
    2
     1 #include<cstdio> 
     2 __int64 a[55]={0,1,1,2};
     3 int  main()
     4 {
     5     int t;
     6     scanf("%d",&t);
     7     for(int i = 4; i <= 50; i++)
     8     {
     9         a[i]=a[i-1]+a[i-2];
    10     }
    11     while(t--)
    12     {
    13         int n;
    14         scanf("%d",&n);
    15         printf("%I64d
    ",a[n]);
    16     }
    17 }
     1 #include<cstdio> 
     2 int a[50]={0,1,1,2};
     3 int  main()
     4 {
     5     int t;
     6     scanf("%d",&t);
     7     while(t--)
     8     {
     9         int n;
    10         scanf("%d",&n);
    11         for(int i = 4; i <= n; i++)
    12         {
    13             a[i]=a[i-1]+a[i-2];
    14         }
    15         printf("%d
    ",a[n]);
    16     }
    17 }
     
    ——将来的你会感谢现在努力的自己。
  • 相关阅读:
    币值转换
    抓老鼠啊!亏了还是赚了
    打印沙漏
    秋季学习总结
    记忆中最深刻的三位老师
    自我介绍
    docker 安装redis 和 mysql
    centos 安装docker
    celery的简单使用
    django redis配置和简单使用
  • 原文地址:https://www.cnblogs.com/yexiaozi/p/5690432.html
Copyright © 2011-2022 走看看