标签:space names += bsp number ret res floor turn
#include <iostream> using namespace std; int jumpFloor(int number) { //递归 //if(number<0)return 0; //if(number==0)return 1; //if(number==1)return 1; //else return (jumpFloor(number-1) + jumpFloor(number-2)); //循坏 int way=1; int pre_way=1; if(number<0)way=0; if(number==0)way=1; if(number==1)way=1; while(number>=2){ int temp=way; way += pre_way; pre_way = temp; number--; } return way; } int Fibonacci(int n) { //递归 //if(n==0 || n==1)return 1; //else return ( Fibonacci(n-1) + Fibonacci(n-2) ); //循坏 int result=1; int pre_result=0; if(n==0) {result=0;} if(n==1) {result=1;} while(n>1){ int temp=result; result += pre_result; pre_result = temp; n--; } return result; } int main() { cout << jumpFloor(3)<< endl; cout << Fibonacci(5)<<endl; return 0; }
标签:space names += bsp number ret res floor turn
原文地址:https://www.cnblogs.com/chuckle/p/9010910.html