relation - 描述尺子长度的递归关系

标签 relation recurrence

在之前的数据结构和算法考试中,我被问到以下问题:

   Consider the following sequences of numbers which are the relative lengths of the subdivisions on a ruler. 
   Write a recurrence relation that describes the length of the ruler as a function of n and solve it.
   1 (when n=1)
   121 (when n=2)
   1213121 (when n=3)
   121312141213121 (when n=4)

我给出的答案是:

 T(n)=2^(n)-1

但是,事实证明这是不正确的,我无法找到正确的答案。如果有人能够提供一些见解,那就太棒了!谢谢!

最佳答案

如果您要构建字符串本身,您可以这样表达:

S(n) := S(n-1)nS(n-1) where S(1) := 1

长度相似:

L(n) := L(n-1) + 1 + L(n-1) = 2L(n-1) + 1

递归关系是用前一项来表达的,这就是你的答案错误的原因。

https://courses.engr.illinois.edu/cs573/fa2010/notes/99-recurrences.pdf

关于relation - 描述尺子长度的递归关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29131771/

相关文章:

javascript - 在 React 状态中保持更新的对象关系

mysql - 当在 master 中插入行时 SQL 在相关中插入行

algorithm - 找到这个算法的递归关系?

algorithm - 解决复发复发

javascript - 计算javascript中一系列日期之间的重复日期

relation - 如何在 Coq 中使用 Rmult 在一个术语中重写 Rle?

Laravel/ Eloquent : Search for rows by value in polymorphed table

一组 (x,y) 点的 C# 数据结构

sql-server-2008 - "neater"节假日计算方式