Download benchmarks/Algorithms/catalan_numbers/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 555 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/catalan_numbers/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/catalan_numbers/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/catalan_numbers/solution.c
555 Bytes
| int id(int n, int x, int y) | |
| { | |
| return x * (n + 1) + y; | |
| } | |
| int solve(int n) | |
| { | |
| int f[64]; | |
| for (int i = 0; i <= n; i++) { | |
| for (int j = 0; j <= n; j++) { | |
| if (i == 0) { | |
| f[id(n, i, j)] = 1; | |
| } | |
| else if (j == 0) { | |
| f[id(n, i, j)] = f[id(n, i-1, j+1)]; | |
| } | |
| else { | |
| f[id(n, i, j)] = f[id(n, i-1, j+1)] + f[id(n, i, j-1)]; | |
| } | |
| } | |
| } | |
| int result = f[id(n, n, 0)]; | |
| return result; | |
| } | |