Problem15

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

Problem15

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
 

看看下面的表格:

Problem15

其实就是杨辉三角嘛

你可能感兴趣的:(J#)