A sequence of N positive integers (10 < N < 100 000), each of them less than or equal 10000, and a positive integer S (S < 100 000 000) are given. Wri ...
分类:
其他好文 时间:
2020-02-29 11:42:15
阅读次数:
107
1、递归:(归去来兮) 递归效率较低,如果明确知道迭代次数,则能用迭代最好用迭代,递归是函数自己调用自身,每次调用都需要入栈等操作。但是递归操作要比迭代简单和清楚。 2、斐波那契数列的递归实现 #include <stdio.h> int Fib(int i); int main() { int i ...
分类:
其他好文 时间:
2020-02-29 00:27:45
阅读次数:
72
第一章 实例1.1斐波那契数列计算 #CalFibonacci.pya,b=0,1while a<1000: print(a,end=',') a,b=b,a+b ...
分类:
编程语言 时间:
2020-02-28 22:49:28
阅读次数:
66
A - Score UVA - 1585 水 #include<bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; while(n--){ int sum=0; string s; cin>>s; int len=s.size ...
分类:
其他好文 时间:
2020-02-28 01:37:26
阅读次数:
71
10.矩形覆盖 题目 我们可以用2 1的小矩形横着或者竖着去覆盖更大的矩形。请问用n个2 1的小矩形无重叠地覆盖一个2 n的大矩形,总共有多少种方法? 比如n=3时,2 3的矩形块有3种覆盖方法: 思路 还是斐波那契数列,2 2的矩阵有两种方法填装,3\ 2的就是3种方法,n\ 2的就是n 1和n ...
分类:
其他好文 时间:
2020-02-26 19:18:47
阅读次数:
80
class Solution { public: int Fibonacci(int n) { int f=0,g=1; while(n--) { f=f+g; int temp = g; g=f; f = temp; } return f; } }; 9这题用递归会溢出 ...
分类:
其他好文 时间:
2020-02-26 01:30:59
阅读次数:
51
大一上学了线代,脑子里面还没有对线代的具体应用有过认识,听说以后机器学习什么的会用上,但好像学到的时候线代知识也容易忘了…… 那么今天就说说在oi里面,我用到线代的知识的题目吧。 矩阵快速幂。 这类题目主要是用来推导公式的,比如经典的斐波那契数列就可以用上这个。 F【n】=F【n-1】+F【n-2】 ...
分类:
其他好文 时间:
2020-02-26 01:30:10
阅读次数:
58
题目传送门 解题思路: 这道题其实就是求一个字符串的所有前缀及其本身的循环节(如果有),思路同另一道题. AC代码: 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 5 using namespace std; 6 7 in ...
分类:
其他好文 时间:
2020-02-25 23:16:14
阅读次数:
63
二分查找和斐波那契查找 1 #include<iostream> 2 using namespace std; 3 class Fib{ 4 public:int f,g; 5 Fib(int n) 6 { 7 f=1,g=0; 8 while(g<n) 9 next();}//因构造函数返回函数 ...
分类:
其他好文 时间:
2020-02-25 14:37:59
阅读次数:
77
1 /* 2 斐波那契数列 3 1、1、2、3、5、8、13、21、34、 4 */ 5 6 #include "stdio.h" 7 8 int main() 9 { 10 int i; 11 int f1, f2, value; 12 int count = 0; //计数 13 f1 = f2 ...
分类:
其他好文 时间:
2020-02-24 21:04:02
阅读次数:
145