Download spoj_cpp_clean/AIBOHP/AIBOHP-9.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/AIBOHP/AIBOHP-9.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/AIBOHP/AIBOHP-9.cpp
-
curl -L -o AIBOHP-9.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/AIBOHP/AIBOHP-9.cpp
1.18 kB
| /* | |
| **************************************************************** | |
| **************************************************************** | |
| -> Coded by Stavros Chryselis | |
| -> Visit my github for more solved problems over multiple sites | |
| -> https://github.com/StavrosChryselis | |
| -> Feel free to email me at stavrikios@gmail.com | |
| **************************************************************** | |
| **************************************************************** | |
| */ | |
| using namespace std; | |
| int DP[6107][6107]; | |
| char str[6107]; | |
| int N; | |
| void init() | |
| { | |
| int i = 0; | |
| char c; | |
| c=gc(); | |
| while(isspace(c)) | |
| c=gc(); | |
| while(!isspace(c) && c!=EOF) | |
| { | |
| str[i++] = c; | |
| c = gc(); | |
| } | |
| N = i; | |
| } | |
| int main() | |
| { | |
| int T, i, j, L; | |
| //freopen("input.txt","r",stdin); | |
| scanf("%d", &T); | |
| while(T--) | |
| { | |
| init(); | |
| for(i=0; i<N; i++) | |
| DP[i][i] = 0; | |
| for(L = 2; L<=N; L++) | |
| for(i=0; i + L - 1 < N; i++) | |
| { | |
| j = i + L - 1; | |
| if(str[i] != str[j]) | |
| DP[i][j] = 1 + min(DP[i+1][j], DP[i][j-1]); | |
| else | |
| DP[i][j] = DP[i+1][j-1]; | |
| } | |
| printf("%d\n", DP[0][N-1]); | |
| } | |
| return 0; | |
| } | |