蒜头爬楼梯
来源:互联网 发布:淘宝皇冠店出售 编辑:程序博客网 时间:2024/04/27 21:18
#include<iostream>#include<cstdio>using namespace std;#define MAXN 50int dp(int i){ if(i==1) return 1; if(i==2) return 2; dp(i)=dp(i-1)+dp(i-2); }int main(){ int n; n=scanf("%d",&n); printf("%d",dp(n));}
使用数组记忆重复结果,优化
<pre name="code" class="cpp">#include<iostream>#include<cstdio>using namespace std;#define MAXN 50int result[100]={0};int dp(int i){ int res; if(result[i]) return result[i]; if(i==0) return 1; if(i==1) return 1; res=dp(i-1)+dp(i-2); result[i]=res; return res; }int main(){ int n; scanf("%d",&n); printf("%d",dp(n));}
0 0
- 蒜头爬楼梯
- 蒜头爬楼梯-动态规划
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 爬楼梯
- 树的中序遍历(非递归实现)
- uva10763 - Foreign Exchange
- 238. Product of Array Except Self &构建乘积数组
- Android Fragment 真正的完全解析(下)
- @RequestMapping之用法
- 蒜头爬楼梯
- CentOS 6.7安装docker
- Android学习:Activity的四种启动方式
- 数据结构和算法分析习题解答之一——引言
- 四种方案解决ScrollView嵌套ListView问题
- 公告字幕滚动开发
- SVN错误:cannot show diff because of inconsistent of newline in the file 的解决方法
- 关于android开发中百度地图地址转换坐标信息的教程
- android的监控日志和测试程序(logcat和强制抛错)