Problem J
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 41 Accepted Submission(s) : 30
Problem Description
有一楼梯共M级,刚开始时你在第一级,若每次只能跨上一级或二级,要走上第M级,共有多少种走法?
Input
输入数据首先包含一个整数N,表示测试实例的个数,然后是N行数据,每行包含一个整数M(1<=M<=40),表示楼梯的级数。
Output
对于每个测试实例,请输出不同走法的数量
Sample Input
2
2
3
Sample Output
1
2
简单水题::
# include <iostream> # include <cstdio> # include <cstring> # include <cmath> # include <string> # include <algorithm> # include <vector> using namespace std; int dp[1001]; int main() { int t; cin >> t; while(t--) { memset(dp, 0,sizeof(dp)); int n; cin >> n; dp[2] = 1; dp[3] = 2; for(int i = 4; i <= n; i++) { dp[i] = dp[i - 1] + dp[i - 2]; } cout << dp[n] << endl; } return 0; }
时间: 2024-11-01 10:46:39