366. Fibonacci【Naive】】的更多相关文章

Find the Nth number in Fibonacci sequence. A Fibonacci sequence is defined as follow: The first two numbers are 0 and 1. The i th number is the sum of i-1 th number and i-2 th number. The first ten numbers in Fibonacci sequence is: 0, 1, 1, 2, 3, 5,…
Insert a node in a sorted linked list. Example Given list = 1->4->6->8 and val = 5. Return 1->4->5->6->8. 解法一: /** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val…
Remove all elements from a linked list of integers that have value val. Example Given 1->2->3->3->4->5->3, val = 3, you should return the list as 1->2->4->5 解法一: /** * Definition for singly-linked list. * struct ListNode { * int…
Count how many nodes in a linked list. Example Given 1->3->5, return 3. 解法一: /** * Definition of ListNode * class ListNode { * public: * int val; * ListNode *next; * ListNode(int val) { * this->val = val; * this->next = NULL; * } * } */ class…
Find the maximum node in a binary tree, return the node. Example Given a binary tree: 1 / \ -5 2 / \ / \ 0 3 -4 -5 return the node with value 3. 解法一: class Solution { public: /** * @param root the root of binary tree * @return the max node */ TreeNod…
[HDU1848]Fibonacci again and again(博弈论) 题面 Hdu 你有三堆石子,每堆石子的个数是\(n,m,p\),你每次可以从一堆石子中取走斐波那契数列中一个元素等数量的石子数,两人轮流取,不能操作者输,判定先后手的胜利. 题解 根据\(SG\)定理,三堆石子可以拆开来看,最终状态的\(SG\)函数为这三堆石子\(SG\)函数的异或值. 那么,我们只需要预处理任意数量石子的\(SG\)值就好了. 对于一堆数量为\(x\)的石子的\(SG\)函数为: \[SG(x)=…
[CF914G]Sum the Fibonacci 题解:给你一个长度为n的数组s.定义五元组(a,b,c,d,e)是合法的当且仅当: 1. $1\le a,b,c,d,e\le n$2. $(s_a|s_b) \& s_c \& (s_d $^$ s_e)=2^i$,i是某个整数3. $s_a \& s_b=0$ 求$\sum f(s_a|s_b) * f(s_c) * f(s_d $^$ s_e)$,f是斐波那契数列,对于所有合法的五元组(a,b,c,d,e).答案模$10^9…
[HDU3117]Fibonacci Numbers 题面 求斐波那契数列的第\(n\)项的前四位及后四位. 其中\(0\leq n<2^{32}\) 题解 前置知识:线性常系数齐次递推 其实后四位还是比较好求,矩阵快速幂就可以了,主要是前四位. 先用线性常系数齐次递推求出斐波那契数列的通项公式 \[ f_n=\frac{\sqrt 5}{5}\left((\frac{1+\sqrt5}{2})^n-(\frac{1-\sqrt5}{2})^n\right) \] 因为数列的前\(39\)项我们…
Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来. 接下来,CodeStar决定要考考他,于是每问他一…
Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17171   Accepted: 11999 Description In the Fibonacci integer sequence, F0 = 0, F1 = 1, and Fn = Fn − 1 + Fn − 2 for n ≥ 2. For example, the first ten terms of the Fibonacci sequen…