#include #include #include #include using namespace std; const int MAX = 1000; int table[MAX][MAX]; int numLength(int a) { if (a < 10) return 1; if (a < 100) return 2; return 3; } int main() { int icase=0; string s; cin >> s; while (s != "0") { icase++; int len = s.length(); for(int i=0; i 1) { // Repetition of a multi character string (parens) int newsol = numLength((j+1)/k) + 2 + table[i][i+k-1]; if (newsol < table[i][i+j]) table[i][i+j] = newsol; } if (valid && k == 1) { // Repetition of a single character string (no parens) int newsol = numLength((j+1)/k) + table[i][i+k-1]; if (newsol < table[i][i+j]) table[i][i+j] = newsol; } } } } } cout << "Case " << icase << ": " << table[0][len-1] << endl; cin >> s; } }