九连环这个玩具,最早在高中的时候摸过,记得解它的时候因为很多重复步骤,所以恨不得要把它拆掉,还好最后解开了,不然我又得加条”亵渎古人智力”的罪名,呵呵。闲话少扯,下面是 n 连环实际步骤数的求法:

gg <- function(n){
a <- numeric(n)
a[1] <- 1
a[2] <- 1
for(i in 3:n){
a[i] <- a[i-1] + 2*a[i-2] + 1
}
a}

比如九连环的实际步骤:

gg(9)

[1]   1   1   4   7  16  31  64 127 256

相关文章:

  • 既然没有了,那就随便看看吧~~

  3 Responses to “n 连环的解法与实际步骤数”

  1. 你你你你!!!!!

  2. 呵呵,谁叫你一直解不开,害得我不能请你吃饭。所以把解法写在这了。

  3. 你你你!你这叫有诚意请我吃饭吗?解法都让你写得这么深奥!!

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 
© 2012 刘思喆 @ 贝吉塔行星 Suffusion theme by Sayontan Sinha