我是靠谱客的博主 粗暴音响,最近开发中收集的这篇文章主要介绍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所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部