Topic Portal
1 /*2 Test instructions: Give a string, successive identical paragraphs can be merged, gogogo->3 (GO), ask the minimum length of the Representation3 interval Dp:dp[i][j] denotes the minimum interval of [i,j] for the length, then dp[i][j] = min (Dp[j][k] + dp[k+1][i+j-1]),4 Digit (i/k) + dp[j][j+k-1] + 2) The latter means that it can be compressed into a string of the same length as K
4.5 Detailed explanation5 */6 /************************************************7 * Author:running_time8 * Created time:2015-8-12 15:28:119 * File Name:UVA_1351.cppTen ************************************************/ One A#include <cstdio> -#include <algorithm> -#include <iostream> the#include <sstream> -#include <cstring> -#include <cmath> -#include <string> +#include <vector> -#include <queue> +#include <deque> A#include <stack> at#include <list> -#include <map> -#include <Set> -#include <bitset> -#include <cstdlib> -#include <ctime> in using namespacestd; - to #defineLson L, Mid, RT << 1 + #defineRson mid + 1, R, RT << 1 | 1 -typedefLong Longll; the Const intMAXN = 2e2 +Ten; * Const intINF =0x3f3f3f3f; $ Const intMOD = 1e9 +7;Panax Notoginseng CharSTR[MAXN]; - intDP[MAXN][MAXN]; the + BOOLCheckintLintRintk) { A inti =0; the while(I <k) { + for(intp=1; l+p*k+i<=r; ++p) { - if(Str[l+i]! = Str[l+p*k+i])return false; $ } $++i; - } - return true; the } - Wuyi intDigitintx) { the intRET =0; - while(x) { Wuret++; X/=Ten; - } About returnret; $ } - - intMainvoid) {//UVA 1351 String Compression - intT scanf ("%d", &T); A while(t--) { +scanf ("%s", str +1); the intlen = strlen (str +1); - for(intI=1; i<=len; ++i) Dp[i][i] =1; $ for(intI=2; i<=len; ++i) { the for(intj=1; j+i-1<=len; ++j) { thedp[j][j+i-1] =INF; the int&x = dp[j][j+i-1]; the for(intK=j; k<i+j-1; ++k) { -x = min (x, dp[j][k] + dp[k+1][i+j-1]); in } the for(intk=1; k<=i/2; ++k) { the if(i% k! =0)Continue; About if(Check (J, i + J-1, K)) { thex = min (x, digit (i/k) + dp[j][j+k-1] +2); the } the } + } - } the Bayiprintf ("%d\n", dp[1][len]); the } the - return 0; -}
Interval DP UVA 1351 String Compression