Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Moca Andrei - solutie 100p
- #include <fstream>
- using namespace std;
- #define dim 4002
- int n, L[dim][dim];
- char A[dim], B[dim], s[dim];
- void SCMaximal()
- {
- ifstream cin("palin.in");
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> s[i];
- for (int i = 1; i <= n; i++)
- {
- A[i] = s[i];
- B[i] = s[n - i + 1];
- }
- for (int i = 1; i <= n; i++)
- for (int j = 1; j <= n; j++)
- if (A[i] == B[j])
- L[i][j] = L[i-1][j-1] + 1;
- else
- L[i][j] = max(L[i-1][j], L[i][j-1]);
- ofstream cout("palin.out");
- cout << n - L[n][n];
- }
- int main()
- {
- SCMaximal();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement