hdu 2041:超级楼梯(水题,递归)】的更多相关文章

超级楼梯 Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted Submission(s): Problem Description 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(<=M<=),表示楼梯的级数. Outpu…
超级楼梯 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 58070    Accepted Submission(s): 29503 Problem Description 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?   Input 输入数据首先包含一个整数N,表示测试实例的个数,然后是…
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 题目分析:题目是真的水,不难发现规律涉及斐波那契数列,就直接上代码吧. 代码如下: #include <iostream> #include <cstring> using namespace std; int t, n, num[40]; int dp(int n) { if (n == 1 || n == 2) return num[n] = n; if (num[n] !=…
题意: 有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法? 思路: 如何到第n阶台阶,只能从n-1和n-2台阶上去,那么只需要计算到n-1阶台阶和到n-2阶台阶即可 代码: #include<iostream> using namespace std; const int maxn = 50; int a[maxn]; void init() { a[1] = 1; a[2] = 1; a[3] = 2; for(int i = 4; i <=…
斐波那契数列,看清题意,当前为第一阶,给出M(每次只能跨1阶或2阶) 从第一阶到M,若M=1,从1-1不用走,0种方法 若M=2 从1-2  一种方法  -> 1.走一次一阶 若M=3 从1-3  两种方法  -> 1.走两次一阶 2.走一次两阶 若M=4 从1-4  三种方法  -> 1.走三次 一阶 2. 走一次一阶 走一次两阶 3.走一次两阶 再走一次一阶 当前项=前两项之和 定义数组 M[1]=0;M[2]=1;M[3]=2;... #include<stdio.h>…
排序 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30009    Accepted Submission(s): 8326 Problem Description 输入一行数字,如果我们把这行数字中的‘5’都看成空格,那么就得到一行用空格分割的若干非负整数(可能有些整数以‘0’开头,这些头部的‘0’应该被忽略掉,除非这个整数就是由若…
Monster 题目链接: http://acm.hust.edu.cn/vjudge/contest/123554#problem/I Description Teacher Mai has a kingdom. A monster has invaded this kingdom, and Teacher Mai wants to kill it. Monster initially has h HP. And it will die if HP is less than 1. Teache…
Hard Code Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=95149#problem/A Description Some strange code is sent to Da Shan High School. It's said to be the prophet's note. The note is extremely hard t…
H - RobotTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87326#problem/H Description A robot is a mechanical or virtual artificial agent, usually an electro-mechanical machine that is guided by a com…
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N…