本文介绍了如何迭代计算此序列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要迭代计算此序列.
A(0,j)=j+1
A(i,0)=A(i-1,0)
A(i,j)=A(i-1,A(i,j-1))
这是我的尝试
public function calculsuite1Action($i,$j)
{
$A = array();
for ($k = 0; $k <= $i * $i * $i + $j; $k++) {
$A[0][$k] = $k + 1;
}
for ($c = 1; $c <= $i; $c++) {
for ($k = 0; $k <= $i * $i * $i + $j - $c; $k++) {
if ($k == 0) {
$A[$c][$k] = $A[$c - 1][1];
} else {
$A[$c][$k] = $A[$c - 1][$A[$c][$k - 1]];
}
if ($c == $i && $k == $j) {
return $A[$i][$j];
}
}
}
}
我正在尝试使用PHP或任何其他编程语言找到解决方案.我该怎么办?
I'm trying to find a solution using PHP or any other programming language.How can I do that?
推荐答案
我尝试为前几个条目寻找模式.如果我没有犯任何错误,则序列非常简单.归结为
I have tried looking for a pattern for the first few entries. If I haven´t done any mistakes the sequence is pretty simple. It boils down to
A(i, j) = j+1
只需使用此JavaScript程序来验证我没有犯任何错误
Just used this JavaScript program to verify I didn't make any mistakes
for (i = 0; i < 5; i++){
for (j = 0; j < 5; j++){
console.log("A("+i+", "+j+") = "+calc(i,j));
}
}
function calc(i, j){
if(i==0)
return j+1;
else if(j == 0)
return calc(i-1, 0);
else
return calc(i-1, calc(i, j-1));
}
这篇关于如何迭代计算此序列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!