Download benchmarks/Algorithms/lcs_n/solution.c from PV-SJTU/PV-Bench: direct link, hf CLI and curl.
- Browser
- Download file 832 Bytes
-
https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/lcs_n/solution.c
- Command line
-
hf download hf://datasets/PV-SJTU/PV-Bench/benchmarks/Algorithms/lcs_n/solution.c
-
curl -L -o solution.c https://huggingface.co/datasets/PV-SJTU/PV-Bench/resolve/main/benchmarks/Algorithms/lcs_n/solution.c
832 Bytes
| int longest_common_sequence(int *x, int *y, int n) | |
| { | |
| int table[1002001]; | |
| int stride; | |
| int i; | |
| int j; | |
| int above; | |
| int left; | |
| stride = n + 1; | |
| i = 0; | |
| while (i <= n) { | |
| table[stride * i] = 0; | |
| i = i + 1; | |
| } | |
| j = 1; | |
| while (j <= n) { | |
| table[j] = 0; | |
| j = j + 1; | |
| } | |
| i = 1; | |
| while (i <= n) { | |
| j = 1; | |
| while (j <= n) { | |
| if (x[i - 1] == y[j - 1]) { | |
| table[stride * i + j] = | |
| table[stride * (i - 1) + (j - 1)] + 1; | |
| } else { | |
| above = table[stride * (i - 1) + j]; | |
| left = table[stride * i + (j - 1)]; | |
| if (above >= left) { | |
| table[stride * i + j] = above; | |
| } else { | |
| table[stride * i + j] = left; | |
| } | |
| } | |
| j = j + 1; | |
| } | |
| i = i + 1; | |
| } | |
| int result = table[stride * n + n]; | |
| return result; | |
| } | |