hdu 1165 Eddy's research II(数学题,递推)
amp 39 HDU II 递推 数学题 Research
2023-09-11 14:20:43 时间
// Eddy 继续
Problem Description
As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function hard to calcuate.
Ackermann function can be defined recursively as follows:
![](http://acm.hdu.edu.cn/data/images/1165-1.jpg)
Now Eddy Gives you two numbers: m and n, your task is to compute the value of A(m,n) .This is so easy problem,If you slove this problem,you will receive a prize(Eddy will invite you to hdu restaurant to have supper).
Ackermann function can be defined recursively as follows:
![](http://acm.hdu.edu.cn/data/images/1165-1.jpg)
Now Eddy Gives you two numbers: m and n, your task is to compute the value of A(m,n) .This is so easy problem,If you slove this problem,you will receive a prize(Eddy will invite you to hdu restaurant to have supper).
Input
Each line of the input will have two integers, namely m, n, where 0 < m < =3.
Note that when m<3, n can be any integer less than 1000000, while m=3, the value of n is restricted within 24.
Input is terminated by end of file.
Note that when m<3, n can be any integer less than 1000000, while m=3, the value of n is restricted within 24.
Input is terminated by end of file.
Output
For each value of m,n, print out the value of A(m,n).
Sample Input
1 3 2 4
Sample Output
5 11
Author
eddy
/********************
看到哦这个题的第一眼感觉像是递推,然后依据那个题目中的公式发现不太好找。就先写了一个递归。打表,然后。恩。找规律……
打表,这才是真正的打表啊……
看到这个表,规律就不用我说了吧……
*************************/
Code:
#include <iostream> #include <string.h> #include <stdio.h> using namespace std; int num[30]; int main() { int i,j,n,m; num[0] = 5; for(i = 1;i<30;i++) num[i] = num[i-1]*2+3; while(cin>>m>>n&&m&&n) { if(m==1) printf("%d\n",n+2); if(m==2) printf("%d\n",2*n+3); if(m==3) printf("%d\n",num[n]); } return 0; }
相关文章
- 验证时出错。HRESULT = '8000000A'
- HDU-1165-Eddy's research II
- HDU 1009:FatMouse' Trade(简单贪心)
- Android Studio 新手常见错误:Gradle DSL method not found: 'runProguard()'
- Linux 下游戏 Me & My Shadow
- 解决 Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
- MySQL: TopN & Rank排名
- DevOps & CI/CD 常见面试题汇总
- 《C++ AMP:用Visual C++加速大规模并行计算》——第1章 C++ AMP概述
- 百度BML&飞桨训练营(十二)【paddle- NLP】评论观点抽取和属性级情感分析
- [Hibernate]Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set
- hdu 1009 FatMouse' Trade
- java.lang.IllegalArgumentException: sheetName '' is invalid
- HDU 4791 Alice's Print Service 水二分
- hdu 4122 Alice's mooncake shop (线段树)
- ZOJ 3587 Marlon's String 扩展KMP
- HDU1164_Eddy's research I【Miller Rabin素数测试】【Pollar Rho整数分解】
- It's about trust
- android4.4系统解决“ERRORcouldn't find native method”方法
- 【UVA】434-Matty's Blocks
- AT&T计划推出免费的省流量功能:针对流媒体 可随时启用/关闭
- python读取配置文件&&简单封装
- DVWA文件上传出现Incorrect folder permissions&The PHP module GD is not installed.的解决方法