0
已采纳
不知道对不对,但应该差不了多少!
void dfs(int pos,int len){
int flag=0;
for(int i=0;i<vec[pos].size();i++){
if(v[vec[pos][i]]<2){
v[vec[pos][i]]++;
flag=1;
dfs(vec[pos][i],len+s[vec[pos][i]].size()-length[pos][vec[pos][i]]);
v[vec[pos][i]]--;
}
}
if(flag==0){
ans=max(ans,len);
return ;
}
}
0
0
0
function pd(s1,s2:string):longint;
var
max,i:longint;
s:string;
begin
max:=10000000;
for i:=1 to length(s1) do
begin
s:=copy(s1,i,length(s1)-i+1);
if(pos(s,s2)=1)and(length(s)<max) then max:=length(s);
end;
if(max=10000000) then exit(-1);
exit(length(s2)-max);
end;
procedure search(t,sum:longint;ss,s1:string);//搜索回溯核心代码
var
i:longint;
begin
if(sum>ans) then ans:=sum;
for i:=1 to n do
if(b[i]<2)and(pos(s[i],s1)=0)and(pd(s1,s[i])<>-1)or(t=1)and(s[i][1]=ss[1]) then
begin
inc(b[i]);
if(t<>1) then search(t+1,sum+pd(s1,s[i]),ss+s[i],s[i])
else search(t+1,length(s[i]),ss+s[i],s[i]);
dec(b[i]);
end;
end;

