Algorithm 这个问题的递归算法是什么?
机器人可以走三种不同长度的步:1厘米、2厘米、3厘米。编写一个递归算法,找出机器人可以通过的不同路径数“d”这将是递归算法Algorithm 这个问题的递归算法是什么?,algorithm,recursion,Algorithm,Recursion,机器人可以走三种不同长度的步:1厘米、2厘米、3厘米。编写一个递归算法,找出机器人可以通过的不同路径数“d”这将是递归算法 int findNumberOfWaysToTraverse(int d) { if (d == 1 || d == 0) // Base case: If the value of d is less than 0 then return 0, and if the value of d is equal to zero then return 1 as it i
int findNumberOfWaysToTraverse(int d)
{
if (d == 1 || d == 0) // Base case: If the value of d is less than 0 then return 0, and if the value of d is equal to zero then return 1 as it is the starting place.
return 1;
else if (d == 2)
return 2;
else
return findNumberOfWaysToTraverse(d - 3) + //recursive calls
findNumberOfWaysToTraverse(d - 2) +
findNumberOfWaysToTraverse(d - 1);
}
你试过什么?您可以通过展示研究成果并将其澄清为具体问题来改进此问题,而不是简单地要求解决方案。看这回答了你的问题吗?