Ackerman
Ackerman
一 . 问题描述及分析

二 . 代码实现
package other;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class bin_1
{
public static void main(String[] args) throws IOException
{
Ackerman myAckerman=new Ackerman(10, 2);
}
}
class Ackerman
{
int m;
int n;
int result;
public Ackerman(int n,int m) throws IOException
{
this.n=n;
this.m=m;
result=ackerman(n,m);
display();
}
public int ackerman(int n,int m)
{
if(n==1&&m==0)
{
return 2;
}
if(n==0&&m>=0)
{
return 1;
}
if(n>=2&&m==0)
{
return n+2;
}
return ackerman(ackerman(n-1,m),m-1);
}
public void display() throws IOException
{
BufferedWriter fout=new BufferedWriter(new FileWriter("out.txt"));
fout.write("result="+result);
fout.flush();
}
}
三 . 运行结果
Ackerman myAckerman=new Ackerman(10, 2);
Ackerman的更多相关文章
- Ackerman函数的栈实现
一.Ackerman函数: ackerman函数的定义如下: 二.Ackerman函数的递归实现: 利用递归来实现ackerman函数是比较简单的: /*Sample Input: 0 1 1 1 S ...
- Ackerman函数
Ackerman函数在许多讲解递归的书中都提到,但似乎又对解题没有太大的意义,暂时不知道了.不过这个东西,是一个数学知识点,暂时收藏于此吧. 查了一下维基百科和百度百科,表面上两个定义不一样,仔细推敲 ...
- Ackerman 函数 (双递归函数)
public static int ackerman(int n,int m){ if(n==1&&m==0){return 2;} else if(n==0&&m ...
- Ackerman 函数
先留个简介: 函数定义: 从定义可以看出是一个递归函数.阿克曼函数不仅值增长的非常快,而且递归深度很高. 一般用来测试编译其优化递归调用的能力.. 如果用一下代码简单实现的话,输入参数4,2程序就直接 ...
- ackerman递归
定义: n+1 n=0 A(m,n)={A(m-1,1) m=0 A(m-1,A(m,n-1)) n>0,m>0 #include <iostream> #inc ...
- [译]C#编码约定
原文:https://msdn.microsoft.com/en-us/library/ff926074.aspx 编码约定的目的是: 创建统一格式的代码,让读者的注意力更集中在内容上面,而不是结构 ...
- C#中的 特性 详解(转载)
本篇幅转载于:http://www.cnblogs.com/rohelm/archive/2012/04/19/2456088.html C#中特性详解 特性提供了功能强大的方法,用于将元数据或声明信 ...
- Calculating Stereo Pairs
Calculating Stereo Pairs Written by Paul BourkeJuly 1999 Introduction The following discusses comput ...
- 最小生成树---Kruskal/Prime算法
1.Kruskal算法 图的存贮采用边集数组或邻接矩阵,权值相等的边在数组中排列次序可任意,边较多的不很实用,浪费时间,适合稀疏图. 方法:将图中边按其权值由小到大的次序顺序选取,若选边后不 ...
随机推荐
- zsh fg: no job control in this shell.
图片的上面就是将一个应用按Ctrl+Z,把任务放到后台里面.没法fg将任务回到前台运行. 在.zshrc中添加set -m. 具体原因不明.我切换到root用户里,没有出现这个问题.将我的.zshrc ...
- 解读Scrapy框架
Scrapy框架基础:Twsited Scrapy内部基于事件循环的机制实现爬虫的并发.原来: url_list = ['http://www.baidu.com','http://www.baidu ...
- WPF中的常用布局
一 写在开头1.1 写在开头评价一门技术的好坏得看具体的需求,没有哪门技术是面面俱到地好. 1.2 本文内容本文主要内容为WPF中的常用布局,大部分内容转载至https://blog.csdn.net ...
- mysql用户管理与备份
用户管理 我们知道在Mysql中root用户是最高权限的用户,其他用户的创建和权限授予都是通过root用户来操作的 查看用户 在root用户界面下 select user,host,password ...
- SpringBoot系列: Spring支持的异常处理方式
===================================视图函数返回 status code 的方式===================================Spring 有 ...
- SpringBoot系列: url重定向和转发
Web UI项目中, 很多 Spring controller 视图函数直接返回 html 页面, 还有一些视图函数是要重定向或转发到其他的 url 上. redirect 和 forward的区别: ...
- 五十二、linux 编程——网络介绍
52.1 网络介绍 使用远程资源 共享信息.程序和数据 分布处理 52.1.1 协议的概念 计算机网络中实现通信必须有一些约定,如对速率.传输代码.代码结构.传输控制步骤和出错控制等约定,这些约定即被 ...
- golang slice分割和append copy还是引用
转载自:http://studygolang.com/articles/724 1. slice1:= slice[0:2] 引用,非复制,所以任何对slice1或slice的修改都会影响对方 dat ...
- 本地图片上传与H5适配知识
最近用到本地图片上传作为API的参数,在网上看了许多,记录一下,以后可能用的着(仅自己记录用,看不清请绕路) function getObjectURL(file) { var url = null ...
- PERFECT NUMBER PROBLEM(思维)
题目链接:https://nanti.jisuanke.com/t/38220 题目大意:这道题让我们判断给定数字是否为完美数字,并给来完美数字的定义,就是一个整数等于除其自身之外的所有的因子之和. ...