洛谷 P10250:[GESP样题 六级] 下楼梯 ← 基础动态规划
【题目来源】https://www.luogu.com.cn/problem/P10250【题目描述】顽皮的小明发现下楼梯时每步可以走 1 个台阶、2 个台阶或 3 个台阶。现在一共有 N 个台阶你能帮小明算算有多少种方案吗【输入格式】输入一行包含一个整数 N。​​​​​​​【输出格式】输出一行一个整数表示答案。【输入样例】4【输出样例】7【数据范围】对全部的测试点保证 1≤N≤60。【算法分析】● 动态规划分析方法https://blog.csdn.net/hnjzsyjyj/article/details/147405964● 本题中数组 dp[] 需要声明为 long long 型。【算法代码】#include bits/stdc.h using namespace std; long long dp[65]; int main() { int n; cinn; dp[0]1; dp[1]1; dp[2]2; dp[3]4; for(int i4; in; i) { dp[i]dp[i-1]dp[i-2]dp[i-3]; } coutdp[n]endl; return 0; } /* in:4 out:7 */【参考文献】https://blog.csdn.net/hnjzsyjyj/article/details/159475660https://blog.csdn.net/hnjzsyjyj/article/details/146540859https://blog.csdn.net/hnjzsyjyj/article/details/113538829

相关新闻

最新新闻

日新闻

周新闻

月新闻