Tag: fibonacci

动态规划问题 – Fibonacci序列

我正在阅读这篇维基百科的文章,并试图在C中实现一个基于’map’的解决方案,其中’map’只是一个int数组,初始化为0。 由于某种原因,它可以达到fib(93) ,然后开始输出奇怪的数字。 如果重要的是我指定-std=c99 : #include #include // represents a fib num typedef unsigned long long fib_t; // the default value of our ‘map’ const int FIB_NULL = 0; // could get from input, set here for now const int FIB_MAX = 100; // our ‘map’ for fib nums static fib_t *fibMap; // calculate the […]

斐波那契搜索

有人请解释我的斐波那契搜索算法。 我已经尝试了很多资源并搜索了很多,但算法仍然不清楚。 大多数资源都将其描述为与二进制搜索相关联,但我不理解它们。 我知道斐波纳契搜索算法是二进制搜索的扩展,我很清楚。 我的书也没能解释。 我知道定义为F(n)= F(n-1)+ F(n-2)的斐波纳契数,所以不需要解释。 通过添加我不理解的内容来更新问题@AnthonyLabarre说: 我正在使用的书有奇怪的符号,没有任何解释。 在这里发布算法,请帮忙。 if(key == a[mid]) return mid; // understood this, comes from binary search if(key > a[mid]) { if(p == 1) return -1; // What is p? It comes as a function arg mid = mid + q; //Now what’s this q? Again comes a function […]

在C中使用共享内存的fibonacci序列

我有一个问题要解决,但它给了我错误: 2009-EE-182-Part2.c: In function ‘main’: 2009-EE-182-Part2.c:35:13: error: expected identifier or ‘(‘ before ‘->’ token 2009-EE-182-Part2.c:40:22: error: expected identifier or ‘(‘ before ‘->’ token 2009-EE-182-Part2.c:41:14: error: expected identifier or ‘(‘ before ‘->’ token 2009-EE-182-Part2.c:42:22: error: expected expression before ‘shared_data’ 2009-EE-182-Part2.c:44:15: error: expected identifier or ‘(‘ before ‘->’ token 2009-EE-182-Part2.c:54:15: error: expected expression before ‘shared_data’ 2009-EE-182-Part2.c:55:19: error: […]

并行化Fibonacci序列生成器

我正在学习并行化,在一个练习中,我给出了一些我应该提高性能的算法。 其中一个是Fibonacci序列生成器: array[0] = 0; array[1] = 1; for (q = 2; q < MAX; q++) { array[q] = array[q−1] + array[q−2]; } 我怀疑这是不能优化的(通过并行化),因为每个数字都取决于前两个数字(因此间接地依赖于所有前面的数字)。 怎么可以并行化呢?

具有线程的递归Fib,分段错误?

任何想法为什么它适用于0,1,2,3,4等值,并且像> 15这样的值的seg故障? #include #include #include void *fib(void *fibToFind); main(){ pthread_t mainthread; long fibToFind = 15; long finalFib; pthread_create(&mainthread,NULL,fib,(void*) fibToFind); pthread_join(mainthread,(void*)&finalFib); printf(“The number is: %d\n”,finalFib); } void *fib(void *fibToFind){ long retval; long newFibToFind = ((long)fibToFind); long returnMinusOne; long returnMinustwo; pthread_t minusone; pthread_t minustwo; if(newFibToFind == 0 || newFibToFind == 1) return newFibToFind; else{ long newFibToFind1 = […]