Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么我的程序一交上去就卡机~~~

Posted by XiLanglang at 2012-08-12 14:48:27 on Problem 1054
var
        n,i,max,cc:longint;
        c:char;
        s:array[0..100] of string;
        a:array[0..100] of longint;
procedure dfs(s1:string);
var
        i,l,t:longint;
        s2,ss1,ss2,ss:string;
        p:boolean;
begin
        if length(s1)>max then max:=length(s1);
        for i:=1 to n do begin
                if a[i]>0 then begin
                        s2:=s[i];
                        if length(s1)<length(s2) then t:=length(s1)
                        else t:=length(s2);
                        l:=1;
                        p:=false;
                        while l<t do begin
                                ss1:=copy(s1,length(s1)-l+1,l);
                                ss2:=copy(s2,1,l);
                                if ss1=ss2 then begin
                                        p:=true;
                                        ss:=s1+copy(s2,l+1,length(s2)-l);
                                        break;
                                end;
                                inc(l);
                        end;
                        if p then begin
                                dec(a[i]);
                                dfs(ss);
                                inc(a[i]);
                        end;
                end;
        end;
end;
begin
        readln(n);
        for i:=1 to n do begin
                readln(s[i]);
                a[i]:=2;
        end;
        readln(c);
        cc:=length(c);
        max:=0;
        for i:=1 to n do begin
                if copy(s[i],1,cc)=c then begin
                        dec(a[i]);
                        dfs(s[i]);
                end;
        end;
        writeln(max);
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator