KK's Steel 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/J Description Our lovely KK has a difficult mathematical problem:he has a meters steel,he will cut it into steels as many as possible,and he doesn't want any two of them be the sam…
''' 实现斐波那契序列,查找其中第N个数的值 ''' def FeiBSequence(list,N): length=len(list); i=0; while i<length: if N<=2 and N>0: return list[N-1]; break; else: z=list[i]+list[i+1]; list.append(z); i+=1; length+=1; if length==N: print list; return list[N-1]; break;…
N 阶楼梯,一次可以爬1.2.3...n步,求爬楼梯的种类数 /** * 斐波那契序列 */ public class ClimbingStairs { // Sol 1: 递归 // 递归 公式:F(n) = F(n - 1) + F(n - 2),n>=2; F(1) = 1, F(0) = 0; // Time: O(1.618 ^ n) Space: O(n) 空间复杂度取决于递归的深度 public int climbStairs1(int n) { if (n < 2) retur…
Given a string S of digits, such as S = "123456579", we can split it into a Fibonacci-like sequence [123, 456, 579]. Formally, a Fibonacci-like sequence is a list F of non-negative integers such that: 0 <= F[i] <= 2^31 - 1, (that is, each…
利用python实现二分法:我的实现思路如下 1.判断要查找的值是否大于最大值,如果大于则直接返回False 2.判断要查找的值是否小于最小值,如果小于则直接返回False 3.如果要查找的值在最大值和最小值之间,则进入循环 a.首先序列的长度要大于1,然后获取序列中间一个值的大小 b.然后和要查找的值做比较,如果相等,则直接返回True,如果不相等,则判断如果中间的值大于要查找的值,则说明要查找的值在该中间值的左边,如果中间的值小于要查找的值,则说明要查找的值在中间的值的右边 c.最后如果序列…
英文版A sequence X_1, X_2, ..., X_n is fibonacci-like if: - n >= 3- X_i + X_{i+1} = X_{i+2} for all i + 2 <= n Given a strictly increasing array A of positive integers forming a sequence, find the length of the longest fibonacci-like subsequence of A.…
已知k阶斐波那契序列的定义为 f(0)=0,f(1)=0,...f(k-2)=0,f(k-1)=1; f(n)=f(n-1)+f(n-2)+...+f(n-k),n=k,k+1,... 试编写求k阶斐波那契序列的第m项值的函数算法,k和m均以值调用的形式在函数参数表中出现. k阶斐波那契序列定义:第k和k+1项为1,前k - 1项为0,从k项之后每一项都是前k项的和 如:k=2时,斐波那契序列为:0,1,1,2,3,5,... k=3时,斐波那契序列为:0,0,1,1,2,4,7,13,...…
转载请注明出处:http://blog.csdn.net/ns_code/article/details/25337983 剑指offer上的第9题,简单题,在九度OJ上測试通过. 主要注意下面几点: 1.用非递归实现,递归会超时 2.结果要用long long保存,不然会发生结果的溢出.从而得到负值 3.假设是在VC++6.0下编译的,long long是illegal的,要用_int64取代.同一时候输出的转化以字符也要用%I64d取代%lld 时间限制:1 秒 内存限制:32 兆 题目描写…
Problem Description Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters steel,he will cut it into steels as many as possible,and he doesn't want any two of them be the same length or any three of them can form a triangle.  …
想了一下发现是斐波那契数列.....水题 #include <stdio.h> #include <algorithm> #include <string.h> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; ; long long n; long long a[maxn]; void init(…