`

Problem15

J# 
阅读更多

题目:Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 20×20 grid?

 

a=Array.new(21){Array.new(21)}

  for i in 1..20
    a[0][i]=1
    a[i][0]=1
  end

1.upto(20) do |i|
  1.upto(20) do |j|
    a[i][j]=a[i-1][j]+a[i][j-1]
  end
end

p a
 

看看下面的表格:

其实就是杨辉三角嘛

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics