ITeye博客

Problem15

mlkimg · 2010-09-11 23:49 · Project Euler · 编程语言 · Markdown

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

How many routes are there through a 2020 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

 

看看下面的表格:

其实就是杨辉三角嘛

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。