/* ACM International Collegiate Programming Contest Central European Regional Contest 2000 Problem I - I-Keyboard Michal Sevcenko */ #include #define MAX_CHARS 100 #define MAX_BUTTONS 100 /* penalty for single character */ int Counts[MAX_CHARS]; /* Dynamic programming buffer, holding minimum penalties for different * button configurations * +-- no. of buttons allocated from the left - 1 * | +-- no. of characters in allocated buttons - 1 * v v */ int Buffer[MAX_BUTTONS][MAX_CHARS]; /* <-- mininum sum of penalties for * allocated buttons */ /* This buffer will be used for reconstruction of the result (widths * of buttons) * +-- no. of buttons allocated from the left - 1 * | +-- no. of characters in allocated buttons - 1 * v v */ int Widths[MAX_BUTTONS][MAX_CHARS];/* <-- optimal no. of characters * excluding the last allocated * button */ /* Array of precomputed penalties for one button with given character * offset and no. of characters * +-- first character in a button * | +-- length of a button - 1 * v v */ int Penalties[MAX_CHARS][MAX_CHARS]; /* <-- penalty */ char CharacterNames[MAX_CHARS]; char ButtonNames[MAX_CHARS]; /* initialize array of precomputed penalties */ void PrecomputePenalties(int chars, int buttons) { int i, j; for (i=0; i 0) { int i; PrintWidths(row-1, Widths[row][column]); printf("%c: ", ButtonNames[row]); for (i=Widths[row][column]+1; i p) { Buffer[i][j] = p; Widths[i][j] = k; } } } } /* printf("Buffer:\n"); for (i=0; i