当前位置:网站首页>[recursive] Ackerman function
[recursive] Ackerman function
2022-07-21 20:32:00 【What does anonymity matter】
Ackermann function is an example of non primitive recursive function ; It requires two natural numbers as input values , Output a natural number . Its output value grows very fast , Is only (4,3) The output of is too large to be calculated accurately .
1920 Late S , Mathematician David · Hilbert's students Gabriel Sudan And William · Ackerman , The basis of calculation was being studied .Sudan Invented a recursive but not primitive recursive Sudan function .1928 year , Ackerman independently came up with another recursive but non primitive recursive function . His initial idea was a function of three variables A(m,n,p), The use of Conway chain arrow notation is m→n→p. Ackermann proved that it is a recursive function . Hilbert is in On the Infinite Guess this function is not primitive recursion . Where's Ackerman On Hilbert’s Construction of the Real Numbers It proves that . later Rozsa Peter and Raphael Robinson A similar function is defined , But only two variables .
Definition :
{ n+1; m=0,n>0
A(m,n) = { A(m-1,1); n=0,m>0
{ A(m-1,A(m,n-1)) n>0,m>0
Code implementation
First of all, you must write a recursive function , The recursive knowledge of this problem is not complicated , Just write according to the title
Recursive function
int ack(int m,int n){
if(m==0){
return n+1;
}
else if(n==0){
return ack(m-1,1);
}
else{
return ack(m-1,ack(m,n-1));
}
}
you 're right , It's that simple .
The whole program
#include<bits/stdc++.h>
using namespace std;
int ack(int m,int n){
if(m==0){
return n+1;
}
else if(n==0){
return ack(m-1,1);
}
else{
return ack(m-1,ack(m,n-1));
}
}
main(){
int m,n;
cin>>m>>n;
cout<<ack(m,n);
}
边栏推荐
- [C语言] 平淡的日子里泛起光 初阶最后的战役
- 2020常州市程序设计小能手真题及题解
- MySQL之账号管理.建库以及四大引擎
- In depth analysis - structure
- [C language] please fly the detailed ability functions and arrays back to the country of light
- [C语言] 0.5倍速讲解世纪大战 有趣的C语言玩法
- (剑指off版)旋转数组求最小值(通俗易懂)
- Let the code solve the series of "linear algebra" - find the greatest common factor of polynomials
- 深度剖析 string —— memset & memcmp
- 无法从“boost::shared_ptr<pcl::RangeImage>”转换为“const std::shared_ptr<const pcl::PointCloud<pcl::PointWit
猜你喜欢
随机推荐
boost::this_thread::sleep (boost::posix_time::microseconds (100000))报错“this_thread”:“::”左侧的符号必须是一种类型
字符函数和字符串函数及其模拟实现(C语言)
P1364 hospital settings
Codeforces 1642B Power Walking
Let the code solve the series of "linear algebra" - find the greatest common factor of polynomials
1023 groups of decimals
1009说反话
[C语言] 选择 循环还可以这样玩 代码表白光之国
[PCB] 3.7V lithium battery -- 5V charge / discharge control circuit -- ip5306 -- drawing board notes
1027 print hourglass
自定义MVC框架实现
第五局 阿卡丽教学局 下 数据分析
VS+QT debug 改成release版本导出记录
Read the manuscript in pieces
自学编程80余年,这些私藏的实用工具&学习网站陪我走到了现在,必须收藏,学习效率翻倍 - 网站篇
[C语言]逃跑吧 跑出这满是烟火味的世俗 C初阶最后战役
第四局 借问酒家何处有?牧童遥指杏花村 下
深度剖析 string —— strcat & strncat
原型、原型链、构造函数、实例的关系
深度剖析 string —— strchr & strstr