汗,Ackerman函数......
来源:互联网 发布:网络不安全事件 编辑:程序博客网 时间:2024/04/29 19:27
数据结构书的习题中看到的,Ackerman函数,它需要两个自然数作为输入值,输出一个自然数。它的输出值增长速度非常高,仅是对于(4,3)的输出已大得不能准确计算。而其反函数的增速奇慢。
环境:Vim + GCC ,Win7 32.
#include <stdio.h>/* * * * * * * * * * * * * * * * * * * * Ackerman函数的递归实现。这个函数的 * 特性是:即使很小的 m 和 n , 他的增长 * 也很迅速,因此得到广泛研究。 * * * * * * * * * * * * * * * * * * */int Ackerman(int m, int n){ /*if (m < 0 || (m != 0 && n < 0) ) { puts("ERROR."); exit(-1); }*/ if (0 == m) { return (n + 1); } if (m > 0 && 0 == n) { return Ackerman(m - 1, 1); } return Ackerman(m - 1, Ackerman(m, n -1) );}int main(void){ int m = 0, n = 0; int result; puts(" Ackerman Function"); printf("Input the m:"); scanf("%d", &m); printf("Input the n:"); scanf("%d", &n); result = Ackerman(m, n); printf("m = %d, n = %d, result = %d.\n", m, n, result); getch(); return 0;}
实际上当m = 4,n = 1 时,就栈溢出而被系统终止了,没法正常运行,或许用迭代的方法好一些。手工计算没一会儿我就投降了,我真心佩服想出这么个函数的人啊!
程序开始,192 K
一直在增长,直到2200 K左右 结程序束
- 汗,Ackerman函数......
- ackerman函数
- Ackerman函数
- Ackerman函数
- ackerman函数
- Ackerman函数
- Ackerman函数
- Ackerman函数
- Ackerman函数
- 关于AckerMan函数
- Ackerman 函数的解法
- “心算“Ackerman函数
- 【记忆化】ackerman函数
- Ackerman 函数
- 递归-Ackerman函数
- 递归之Ackerman函数
- 【记忆化搜索】Ackerman函数
- 求Ackerman函数的值
- HDOJ - 2238 机器人的舞蹈II
- 談Linux Kernel巨集 do{...}while(0) 的撰寫方式
- oracle10g 如何开启归档模式
- Spring配置数据源的三种方式 (dbcp,c3p0,jndi).
- “1000万字符串,去掉重复”的一些思考和java实现
- 汗,Ackerman函数......
- python异常如何全面捕获
- 第七周实验报告(二)
- 高级排序算法--快速排序
- 抓取
- oracle 游标
- Linux Kernel 排程機制介紹
- 整合IIS和Tomcat失败之后,原网站打不开,出现Service Unavailable 解决办法!!
- Cocos2d-x CCTMXTiledMap类