mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
feat: add dynamic_programming
to CMake lists
This commit is contained in:
parent
b1a8da69a8
commit
c064a7740a
@ -65,6 +65,7 @@ add_subdirectory(process_scheduling_algorithms)
|
||||
add_subdirectory(numerical_methods)
|
||||
add_subdirectory(math)
|
||||
add_subdirectory(cipher)
|
||||
add_subdirectory(dynamic_programming)
|
||||
|
||||
## Configure Doxygen documentation system
|
||||
cmake_policy(SET CMP0054 NEW)
|
||||
|
18
dynamic_programming/CMakeLists.txt
Normal file
18
dynamic_programming/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# If necessary, use the RELATIVE flag, otherwise each source file may be listed
|
||||
# with full pathname. The RELATIVE flag makes it easier to extract an executable's name
|
||||
# automatically.
|
||||
|
||||
file( GLOB APP_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.c )
|
||||
foreach( testsourcefile ${APP_SOURCES} )
|
||||
string( REPLACE ".c" "" testname ${testsourcefile} ) # File type. Example: `.c`
|
||||
add_executable( ${testname} ${testsourcefile} )
|
||||
|
||||
if(OpenMP_C_FOUND)
|
||||
target_link_libraries(${testname} OpenMP::OpenMP_C)
|
||||
endif()
|
||||
if(MATH_LIBRARY)
|
||||
target_link_libraries(${testname} ${MATH_LIBRARY})
|
||||
endif()
|
||||
install(TARGETS ${testname} DESTINATION "bin/dynamic_programming") # Folder name. Do NOT include `<>`
|
||||
|
||||
endforeach( testsourcefile ${APP_SOURCES} )
|
@ -31,8 +31,8 @@ void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B) {
|
||||
|
||||
/* loop over the simbols in my sequences
|
||||
save the directions according to the LCS */
|
||||
for (i = 1; i <= l1; ++i)
|
||||
for (j = 1; j <= l2; ++j)
|
||||
for (i = 1; i <= l1; ++i) {
|
||||
for (j = 1; j <= l2; ++j) {
|
||||
if (s1[i-1] == s2[j-1]) {
|
||||
L[i][j] = 1 + L[i-1][j-1];
|
||||
B[i][j] = DIAG;
|
||||
@ -44,7 +44,9 @@ void lcslen(const char *s1, const char *s2, int l1, int l2, int **L, int **B) {
|
||||
else {
|
||||
L[i][j] = L[i-1][j];
|
||||
B[i][j] = UP;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,10 +78,12 @@ char *lcsbuild(const char *s1, int l1, int l2, int **L, int **B) {
|
||||
i = i - 1;
|
||||
j = j - 1;
|
||||
}
|
||||
else if (B[i][j] == LEFT)
|
||||
j = j - 1;
|
||||
else
|
||||
i = i - 1;
|
||||
else if (B[i][j] == LEFT) {
|
||||
j = j - 1;
|
||||
}
|
||||
else {
|
||||
i = i - 1;
|
||||
}
|
||||
}
|
||||
return lcs;
|
||||
}
|
||||
@ -133,8 +137,9 @@ static void test() {
|
||||
printf("LCS: %s\n", lcs);
|
||||
|
||||
free(lcs);
|
||||
for (j = 0; j <= l1; j++)
|
||||
free(L[j]), free(B[j]);
|
||||
for (j = 0; j <= l1; j++) {
|
||||
free(L[j]), free(B[j]);
|
||||
}
|
||||
free(L);
|
||||
free(B);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user