Test instructions: Removes M characters from a string of length N to minimize the dictionary order of the resulting new string
Idea: Reverse Construction
1#include"bits/stdc++.h"2 using namespacestd;3 Const intMAXN =100010;4 intN;5 CharANS[MAXN];6 intmin[maxn][ -], max[maxn][ -];7 8 //built St table, ANS[MAXN], n is called after read in9 voidMAKERMQ ()Ten { One intI, J, Len; A for(i =1; I <= N; ++i) { -min[i][0] = max[i][0] =i; - } the - intp, q; - for(j =1; (len =1<< j) <= N; ++j) { - for(i =1; i + Len-1<= N; ++i) { +p = min[i][j-1]; -Q = min[i + (len >>1)][j-1]; + if(Ans[p] < Ans[q] | | (Ans[p] = = Ans[q] && p <q)) { AMIN[I][J] =p; at } - Else { -MIN[I][J] =Q; - } - - //p = max[i][j-1]; in //q = max[i + (len >> 1)][j-1]; - //if (ans[p] > Ans[q] | | (Ans[p] = = Ans[q] && p < q)) { to //max[i][j] = p; + // } - //else { the //max[i][j] = q; * // } $ }Panax Notoginseng } - } the + //the minimum and maximum values for [L, R] are placed in MinValue and MaxValue and do not require initialization of minValue and MaxValue A voidAskintLintRint&Min_pos) the { + intPow_num, Len, p, Q; -Pow_num =int(Log (R-l +1)/log (2)); $Len =1<<Pow_num; $ -p =Min[l][pow_num]; -Q = Min[r-len +1][pow_num]; the if(Ans[p] < Ans[q] | | (Ans[p] = = Ans[q] && p <q)) { -Min_pos =p;Wuyi } the Else { -Min_pos =Q; Wu } - About //p = max[l][pow_num]; $ //q = Max[r-len + 1][pow_num]; - //if (ans[p] > Ans[q] | | (Ans[p] = = Ans[q] && p < q)) { - //maxValue = ans[p]; - // } A //else { + //maxValue = ans[q]; the // } - } $ Charres[1010]; the inttot; the intm; the the intMain () - { in while(SCANF ("%s%d", ans +1, &m)! =EOF) { thetot =0; then = strlen (ans +1); About makermq (); the intCNT = n-m; the intMin_pos; the intL =1, r = m +1; + while(cnt--) { - Ask (L, R, Min_pos); theres[tot++] =Ans[min_pos];BayiL = Min_pos +1; the++R; the } -Res[tot] =' /'; - intindex =0; the while(Index <= tot-1&& Res[index] = ='0') { the++index; the } the if(Index = =tot) { -printf"0\n"); the Continue; the } theprintf"%s\n", Res +index);94 } the}
HDU 3183 St Table