Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Count Grid Paths

Count routes across a rectangular grid using only right and down moves.

Start at the top-left corner of a grid with rows by columns cells. Move along cell edges only, one edge right or one edge down at a time, until reaching the bottom-right corner. Count distinct move sequences. The grid has no obstacles.

A grid with 2 rows and 3 columns of cells needs exactly 2 down moves and 3 right moves.

Implement lattice_paths(rows, columns).

Input

rows: The number of rows of cells, not vertices.

columns: The number of columns of cells, not vertices.

Output

Return the number of corner-to-corner routes.

Ràng buộc

0 ≤ rows, columns ≤ 30 and rows + columns ≤ 60. Zero in one dimension gives a straight route. A 0 × 0 grid has one empty route. Counts fit signed 64-bit.

Ví dụ

Ví dụ 1
Đầu vào:
rows = 2
columns = 3

Kết quả mong đợi:
expected = 10
Đầu vào:
long long rows = 2;
long long columns = 3;

Kết quả mong đợi:
long long expected = 10;
Đầu vào:
long rows = 2;
long columns = 3;

Kết quả mong đợi:
long expected = 10;

Giải thích

Every route contains five moves. Choosing which two are down gives ten distinct routes.

Ví dụ 2
Đầu vào:
rows = 0
columns = 4

Kết quả mong đợi:
expected = 1
Đầu vào:
long long rows = 0;
long long columns = 4;

Kết quả mong đợi:
long long expected = 1;
Đầu vào:
long rows = 0;
long columns = 4;

Kết quả mong đợi:
long expected = 1;

Giải thích

There is only the straight route of four right moves.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.