a0=1、a1=1、a2=a1+a0、a3=a2+a1,以此类推,请写代码用递归算出a30?

public class Test {
    public static void main(String[] args) {
        System.out.println(recursive(30));

    }
    public static int recursive(int i){
//        int a0=1;
//        int a1=1;
//        int a2=a1+a0;
//        int a3=a2+a1;
        if (i==0||i==1) return 1;
        return recursive(--i)+recursive(--i);
    }
}
时间: 2024-08-26 01:40:02

a0=1、a1=1、a2=a1+a0、a3=a2+a1,以此类推,请写代码用递归算出a30?的相关文章

多种方式计算多项式a0+a1*x+a2*x^2+a3*x^3+.......(计算效率与算法的重要性)

问题描述: 两种方式计算多项式a0+a1*x+a2*x^2+a3*x^3+.......(普通算法以及秦九韶算法)在某处x的值,通过调用<time.h>中的函数tick(),计算两种方式的运算时间,得出.....预知结论为何,请看下面代码: 代码如下: #include<stdio.h> #include<math.h> //pow #include<time.h> //tick #define MAXODER 300 //最大阶乘数 #define REP

Video for Linux Two API Specification revision0.24【转】

转自:http://blog.csdn.net/jmq_0000/article/details/7536805#t136 Video for Linux Two API Specification Revision 0.24 Michael H Schimek <[email protected]> Bill Dirks Hans Verkuil Martin Rubli Copyright © 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,

Video for Linux Two API Specification Revision 2.6.32【转】

转自:https://www.linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/spec-single/v4l2.html Video for Linux Two API Specification Revision 2.6.32 Michael H Schimek <[email protected]> Bill Dirks Original author of the V4L2 API and documentation. Hans

地图裁剪

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms; namespace WindowsFormsApplic

一条汇编指令引发的 蝴蝶效应

系统 : Windows xp 程序 : crackme1 程序下载地址 :http://pan.baidu.com/s/1gdY4wMJ 要求 : 分析算法 使用工具 :OD 可在“PEDIY CrackMe 2007”中查找关于此程序的讨论,标题为“muckis's crakcme #1破解(检测OD)”. OD载入程序,键入命令:bp GetWindowTextA,成功断下,并返回程序领空: 004014A0 |. 68 EA030000 push 3EA ; /ControlID = 3

bzoj 2286: [Sdoi2011消耗战

1 #include<cstdio> 2 #include<iostream> 3 #define M 1000009 4 #define N 250009 5 #define ll long long 6 #define inf 1000000000000000000LL 7 #include<algorithm> 8 using namespace std; 9 int n,head[N],next[M],u[M],cnt,fa[N][22],deep[N],m,h

python自动化之excel

import openpyxl wb=openpyxl.load_workbook(r'C:\Users\Administrator\Desktop\sl.xlsx') type(wb) wb.get_sheet_names() sheet=wb.get_sheet_by_name('o') type(sheet) sheet.title anotherSheet=wb.get_active_sheet()  #######得到活动页sheet anotherShee #############

【JS工具对象系列】(1)URL工具对象

分享自己的js工具对象,如下为URL工具代码: urlUtil={ /** * 返回当前页面的url * @author chencha * @since 2014-07-04 */ getURL: function() { return document.URL; //大写哦! }, /** 返回url参数数组,分别有name和value属性 * @param {String} url - url字符串 * @author chencha * @since 2014-07-04 */ getU

PHP面试试题

1,用PHP打印出前一天的时间,格式是2006-5-10 22:21:21echo date("Y:m:d H:i:s",strtotime("-1 day"));?>2,echo(),print(),print_r()的区别echo是语言结构,无返回值;print功能和echo基本相同,不同的是print是函数,有返回值;print_r是递归打印,用于输出数组对象3,能够使HTML和PHP分离开使用的模板smarty, PHPLib, FastTemplat