/* Palindrome (IOI 2000) Copyright (C) 2000 Paolo Boldi and Sebastiano Vigna This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Il programma si basa sull'idea che se f(w) e` il minimo numero di caratteri che rende w palindroma, allora f(awa)=f(w) e f(awb) = min{f(wb), f(aw)}+1. La dimostrazione e` data a parte. Dato che la matrice necessaria per calcolare per programmazione dinamica f e` 5000x5000, ma d'altra parte per calcolare la riga i ci servono solo le righe i-1 e i-2, utilizziamo sempre le stesse tre righe da 5000 elementi ciclicamente. */ #include #include #include #include #include #define min(a,b) ((a)<(b)?(a):(b)) #define MAXLUN 5000 #define MINLUN 3 char parola[MAXLUN]; int ott[3][MAXLUN]; /* Le tre righe usate ciclicamente per la programmazione dinamica. */ FILE *F; int main(int argc, char *argv[]) { int k, i, N; FILE *F; F = stdin; fscanf(F, "%d\n", &N); for(i=0; i