标签:
提示:100%的数据中,N<=50.
50%的数据中,N<=20.
题解:。。。实际上别老想着DP、二分、哈希啥的高端算法,事实证明暴力一样也能0msA掉题目——直接上来枚举前缀串,然后算出变化距离,然后打擂台弄出最小的即可
1 /************************************************************** 2 Problem: 1789 3 User: HansBug 4 Language: Pascal 5 Result: Accepted 6 Time:0 ms 7 Memory:352 kb 8 ****************************************************************/ 9 10 var 11 i,j,k,l,m,n,ans:longint; 12 a,b,c,s:ansistring;ch:char; 13 function min(x,y:longint):longint; 14 begin 15 if x<y then min:=x else min:=y; 16 end; 17 function cal(x,y:ansistring):longint; 18 var i:longint; 19 begin 20 for i:=1 to min(length(x),length(y)) do 21 if x[i]<>y[i] then break; 22 if x[i]<>y[i] then dec(i); 23 exit(length(x)-i+length(y)-i); 24 end; 25 begin 26 readln(i,ch,a); 27 readln(i,ch,b); 28 readln(i,ch,c); 29 ans:=length(a)+length(b)+length(c); 30 s:=‘‘; 31 for i:=1 to length(a) do 32 begin 33 s:=s+a[i]; 34 ans:=min(ans,cal(s,a)+cal(s,b)+cal(s,c)); 35 end; 36 s:=‘‘; 37 for i:=1 to length(b) do 38 begin 39 s:=s+b[i]; 40 ans:=min(ans,cal(s,a)+cal(s,b)+cal(s,c)); 41 end; 42 s:=‘‘; 43 for i:=1 to length(c) do 44 begin 45 s:=s+c[i]; 46 ans:=min(ans,cal(s,a)+cal(s,b)+cal(s,c)); 47 end; 48 writeln(ans); 49 readln; 50 end.
标签:
原文地址:http://www.cnblogs.com/HansBug/p/4470677.html