中級 0件解決済み 正答率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.

制約

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.

例

例 1
入力:
rows = 2
columns = 3

期待される出力:
expected = 10
入力:
long long rows = 2;
long long columns = 3;

期待される出力:
long long expected = 10;
入力:
long rows = 2;
long columns = 3;

期待される出力:
long expected = 10;

解説

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

例 2
入力:
rows = 0
columns = 4

期待される出力:
expected = 1
入力:
long long rows = 0;
long long columns = 4;

期待される出力:
long long expected = 1;
入力:
long rows = 0;
long columns = 4;

期待される出力:
long expected = 1;

解説

There is only the straight route of four right moves.

参考資料

この課題はCodeUtility用に調整されています。上記の説明と制約に従ってください。

他の人の解答から学ぶ

コミュニティの解答

まだ公開された解答がありません。この課題を解いて最初の解答を共有しましょう。