Starting in the top left corner of a 2
2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a 20
20 grid?
Prelude> :m Math.Combinat.Numbers
Prelude Math.Combinat.Numbers> 21 * catalan 20
137846528820
My first code is ... calculate so long long time.
latticeNo (x, 2) = x
latticeNo (2, y) = y
latticeNo (x, 3) = latticeNo (x - 1, 3) + x
latticeNo (3, y) = latticeNo (y - 1, 3) + y
latticeNo (x, y) = latticeNo (x - 1, y) + latticeNo (x, y - 1)
Second code is ... use combination. I'll try to know more general method.
Google tell me about Catalan number. See カタラン数
Google tell me about Catalan number. See カタラン数
댓글 없음:
댓글 쓰기