超级楼梯 hdu

来源:互联网 发布:深度睡眠软件 编辑:程序博客网 时间:2024/06/05 06:08

数论在acm是非常重要的,适合起步练习,但是他在dp等很多地方都会涉及,因此,一定要打好数论的基础,这里先讲一下超级楼梯吧。
http://acm.hdu.edu.cn/showproblem.php?pid=2041
当读完题目的时候,就发现,这其实就是一道斐波那契数列的扩展题。所以这里我直接贴代码,另外给大家贴一个斐波那契扩展链接,有兴趣的朋友可以做一下哦!http://acm.hdu.edu.cn/showproblem.php?pid=2018(简单递推)
http://acm.hdu.edu.cn/showproblem.php?pid=2044(斐波那契数列扩展)

代码:

#include <iostream>#include <cstdio>using namespace std;int main(){    int a[45];    int m;    int n;    while (scanf("%d", &n)!=EOF){        while (n--) {            scanf("%d",&m);            a[0] = 1;            a[1] = 1;            for (int i = 2;i < 44;i++) {                a[i] = a[i - 1] + a[i - 2];            }            printf("%d\n", a[m - 1]);        }    }    return 0;}
0 0