我是靠谱客的博主 粗暴音响,这篇文章主要介绍codevs1018,现在分享给大家,希望可以做个参考。

题目地址:http://codevs.cn/problem/1018/

分析:

深搜

代码:

var word:array[1..200] of string;

      w:array[1..200] of longint;

      i,n:longint;

      a:string;

      dragon:string;

      maxlen:longint;

procedure search(s:string;x:longint);

var i:longint;

      len:string;

      max:longint;

begin

      max:=0;

      len:=copy(s,length(s)-x+1,255);

      if len <> s then

      begin

            for i := 1 to n do if w[i] <> 2 then

            begin

                  if pos(len,word[i]) > max then max:=pos(len,word[i]);

                  if pos(len,word[i]) = 1 then 

                  begin

                        s:=s+copy(word[i],length(len)+1,255);

                        inc(w[i]);

                        search(s,1);

                        dec(w[i]);

                        delete(s,length(s)-length(copy(word[i],length(len)+1,255))+1,255);

                  end;

            end;

            if max = 0 then 

            begin

                  if length(s) > maxlen then maxlen:=length(s);

                  exit;

            end;

            search(s,x+1);

      end

      else

      if length(s) > maxlen then maxlen:=length(s);

      end;


begin

      fillchar(w,sizeof(w),0);

      readln(n);

      for i := 1 to n do readln(word[i]);

      read(a);

      for i := 1 to n do 

      begin

            if pos(a,word[i]) = 1 then 

            begin

                  dragon:=word[i];

                  inc(w[i]);

                  search(dragon,1);

                  dec(w[i]);

            end;

      end;

      write(maxlen);

end.


最后

以上就是粗暴音响最近收集整理的关于codevs1018的全部内容,更多相关codevs1018内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(103)

评论列表共有 0 条评论

立即
投稿
返回
顶部