|
|
back to boardCommon BoardTo Tran Nam Trung(+) Thank you Tran Nam Trung for your help on problem 1183. But I didn't understand your idea. Can you explain it more clearly(espesially about [i,j] - what i,j mean?) Re: To Tran Nam Trung(+) > Thank you Tran Nam Trung for your help on problem 1183. But I didn't > understand your idea. Can you explain it more clearly(espesially > about [i,j] - what i,j mean?) Very happy to help you. D[i,j] means the minnimum number of characters needed to change the sequence from i to j become correct sequence. So the answer to the prob is D[1,length(s)]. If you still don't understand me, email me at : trungduck@yahoo.com I use DP. My program works fine on all NEERC tests but on Timus it get WA! Why? Please, help me!!!(+) Program t1183; Const MaxN = 100; Var D : array[1..MaxN,1..MaxN]of byte; i,j,k,q : integer; len : integer; min : integer; S : String; Function GetAns(l1,l2 : byte) : String; Var j : integer; begin if l1=l2 then begin if (s[l1]='(')or(s[l2]=')') then begin GetAns:='()'; exit; end; if (s[l1]='[')or(s[l2]=']') then begin GetAns:='[]'; exit; end; end; if ((s[l1]='(')and(s[l2]=')'))or ((s[l1]='[')and(s[l2]=']')) then begin if l1+1<=l2-1 then if D[l1,l2]=D[l1+1,l2-1] then begin GetAns:=s[l1]+GetAns(l1+1,l2-1)+s[l2]; exit; end; if l1+1>l2-1 then begin GetAns:=s[l1]+s[l2]; end; end; for j:=l1 to l2-1 do if D[l1,j]+D[j+1,l2]=D[l1,l2] then begin GetAns:=GetAns(l1,j)+GetAns(j+1,l2); exit; end; end; begin Readln(S); len:=length(S); if len=0 then begin Writeln(''); Halt; end; fillchar(D,SizeOf(D),255); for i:=1 to len do D[i,i]:=1; for k:=1 to len-1 do for i:=1 to len-k do for j:=i+k to len do begin if ((s[i]='(')and(s[j]=')'))or ((s[i]='[')and(s[j]=']')) then if i+1<=j-1 then D[i,j]:=D[i+1,j-1] else D[i,j]:=0; for q:=i to j-1 do if D[i,q]+D[q+1,j]<D[i,j] then D[i,j]:=D[i,q]+D[q+1,j]; end; Writeln(GetAns(1,len)); end. Re: I use DP. My program works fine on all NEERC tests but on Timus it get WA! Why? Please, help me!!!(+) I don't know why. You can try with this test : Input : 100 chacacters "(". I get AC. I changed my code for a little: I add all compiler options! It's judge bug!!! > I don't know why. You can try with this test : Input : 100 > chacacters "(". |
|
|