Solve by explicitly counting the paths with dynamic programming. >>> solution(6) 924 >>> solution(2) 6 >>> solution(1) 2
(n: int = 20)
| 8 | |
| 9 | |
| 10 | def solution(n: int = 20) -> int: |
| 11 | """ |
| 12 | Solve by explicitly counting the paths with dynamic programming. |
| 13 | |
| 14 | >>> solution(6) |
| 15 | 924 |
| 16 | >>> solution(2) |
| 17 | 6 |
| 18 | >>> solution(1) |
| 19 | 2 |
| 20 | """ |
| 21 | |
| 22 | counts = [[1 for _ in range(n + 1)] for _ in range(n + 1)] |
| 23 | |
| 24 | for i in range(1, n + 1): |
| 25 | for j in range(1, n + 1): |
| 26 | counts[i][j] = counts[i - 1][j] + counts[i][j - 1] |
| 27 | |
| 28 | return counts[n][n] |
| 29 | |
| 30 | |
| 31 | if __name__ == "__main__": |