斐波那契dp
来源:互联网 发布:对数据标准化 编辑:程序博客网 时间:2024/06/17 15:28
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Note: Given n will be a positive integer.
题目来源于https://leetcode.com/problems/climbing-stairs/#/description
题目的意思是给你n级台阶,每次只能上1,2级台阶,总共有多少种方法?
测试数据n=70结果696897233
简单的递归
long long dfs(int n){ if(n==0)return 1; if(n==1)return 1; return dfs(n-1)+dfs(n-2);}
数据量大,递归的次数太多,内存容易爆炸
增量化模型
int dp[100];long long dfs(int n){ if(n==1)return 1; dp[0]=1; dp[1]=1; for(int i=2;i<=n;i++) { dp[i]=dp[i-1]+dp[i-2]; } return dp[n];}
滚动数组
long long climbStairs(int n){ if (n <= 2) { return n; } int num1 = 1; int num2 = 2; int res = 0; for (int i = 2; i < n; i++) { res = num1 + num2; num1 = num2; num2 = res; } return res;}
0 0
- 斐波那契dp
- 斐波那契数列 dp
- 台阶 dp 斐波那契
- 【斐波那契DP】HDU 4639——HeHe
- 斐波那契,DP,递归,递推,数学归纳
- hdoj 2046 骨牌铺方格 【DP】+【斐波那契】
- hihoCoder1143 DP 斐波那契数列矩阵快速幂
- hihocoder 1164 随机斐波那契 (期望dp)
- 剑指offer-斐波那契数列-DP
- hdu 2044 2501 一只小蜜蜂#DP#斐波那契#java水大数
- 关于矩阵乘法优化dp(入门+斐波那契模板题)
- leetcode 70. Climbing Stairs DP动态规划 + 斐波那契序列
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- 斐波那契
- Bootstrap轮播图
- 信息系统项目管理知识--信息系统建设
- 自定义ListView实现任意View跑马灯效果
- Binary Tree Postorder Traversal
- python爬网页存入本地文件
- 斐波那契dp
- springMVC其实跟JSPMVC大同小异
- Fatal error: Can't open and lock privilege tables: Table 'mysql.host' doesn't exist
- 注意""与null的区别
- C编译: makefile基础
- 欢迎使用CSDN-markdown编辑器
- GIT部署(三)GIT 远程仓库:添加远程库、从远程库克隆
- leetCode---Subsets
- windows下python安装xgboost