DP 1010
来源:互联网 发布:阿里云磁盘快照 编辑:程序博客网 时间:2024/05/16 08:12
Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
Output
对于每个测试实例,请输出不同走法的数量
Sample Input
223
Sample Output
12
解题思路:从第4阶开始,第i阶的方法为i-1的方法加上i-2的方法
感想:依旧是水题……
AC代码:
#include<iostream>using namespace std; int main(){int a[1000];int n;a[1] = 1;a[2] = 1;a[3] = 2;cin >> n ;while(cin >> n){if(n>=1&&n<=3)cout << a[n] << endl ;else {for(int i = 4;i <= n ; i ++)a[i] = a[i - 1] + a[i -2];cout << a[n] << endl;}}return 0;}
0 0
- DP 1010
- Timus 1010 DP
- SDAU dp专题 1010
- BZOJ 1010 斜率DP
- dp
- dp
- dp
- 【DP】
- dp
- dp
- DP
- DP
- DP
- DP
- DP
- dp
- DP
- dp
- iOS 延迟执行的几种方式 —— HERO博客
- 构造MaxTree
- sql随机查询数据
- CSS预处理器
- 【Qt】标准文件对话框
- DP 1010
- http 头信息详解
- 关于codeblocks的调试问题
- 解决提示 The node "nios_sys:nios_sys_inst|sdram:the_sdram|za_data[0]" has multiple drivers due错误
- html5获取地理位置
- HDU 1877 又一版 A+B
- Action ***cannot be found in the namespace
- Ubuntu使用过程中遇到的问题及解决办法
- hdu3081 Marriage Match II