Read the Lujiaxin blog, feel good waves ah .... I'm sorry.
Brush the question when the time is not enough, each algorithm is written only one or two passes, so how can progress
Don't always complain that time is too little, you do not work hard >_<
Well, look at the problem.
N<=50 Range, Memory ... N^3
F[a][b][t] Indicates that there is no shortest answer to M a~b in this interval.
Enumerate breakpoints (very important idea), when T==1, apparently on the right side of the left are DP a bit; (think clearly)
Then, see if the left can be compressed, this sentence is very important, because if there is no m in the interval, it can only be the leftmost copy of copy, so can be guaranteed correctness;
Standard thinking good rigorous ah, feel their DP ability to learn more
Ps.submit when you see someone else doing 3110, code really very short tree sets of trees, well want to write AH ~
Monthly Exam Refueling ~\ (≧▽≦)/~
#include <cstdio>#include<algorithm>#include<cstring>Chars[ $];intf[ -][ -][2],mark[ -][ -][2];using namespacestd;BOOLSame (intAintb) { intl=b-a+1;if(l%2==1)return 0; for(inti=a;i<= (A+B)/2; i++) if(s[i]!=s[i+l/2])return 0; return 1; }intdpintAintBintt) { inttmp=b-a+1, l=b-a+1;if(tmp==1)return 1; if(Mark[a][b][t])returnf[a][b][t];mark[a][b][t]=1; if(t>0) for(inti=a;i<b;i++) Tmp=min (TMP,DP (A,i,1) +DP (i+1B1)+1); for(inti=a;i<b;i++) Tmp=min (TMP,DP (a,i,t) +b-i); if(Same (A, b)) Tmp=min (TMP,DP (A, (a+b)/2,0)+1); F[a][b][t]=tmp;returntmp;}intMain () {scanf ("%s", s+1); intLen=strlen (s+1); printf ("%d", DP (1Len1)); }
View Code
[bzoj1068] Compression [interval motion regulation]