{"id":267,"date":"2012-11-15T15:21:00","date_gmt":"2012-11-15T07:21:00","guid":{"rendered":"http:\/\/nike0good.jp1.rpvhost.net\/172"},"modified":"2012-11-15T15:21:00","modified_gmt":"2012-11-15T07:21:00","slug":"poj_1226_longest_common_substring_containing_reverse_order","status":"publish","type":"post","link":"https:\/\/nike0good.com\/?p=267","title":{"rendered":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09"},"content":{"rendered":"<table border=\"0\" width=\"100%\" background=\"http:\/\/poj.org\/images\/table_back.jpg\" style=\"font-family:Simsun\">\n<tbody>\n<tr>\n<td>\n<div style=\"position:absolute; right:10px\">Language:<select size=\"1\"><option value=\"default\" selected=\"selected\"><br \/>\nDefault<\/option><\/select><\/div>\n<div class=\"ptt\" lang=\"en-US\" style=\"text-align:center; font-size:18pt; font-weight:bold; color:blue\">\nSubstrings<\/div>\n<div class=\"plm\" style=\"text-align:center; font-size:12pt\">\n<table align=\"center\">\n<tbody>\n<tr>\n<td><strong>Time Limit:<\/strong>&nbsp;1000MS<\/td>\n<td width=\"10px\">&nbsp;<\/td>\n<td><strong>Memory Limit:<\/strong>&nbsp;10000K<\/td>\n<\/tr>\n<tr>\n<td><strong>Total Submissions:<\/strong>&nbsp;9639<\/td>\n<td width=\"10px\">&nbsp;<\/td>\n<td><strong>Accepted:<\/strong>&nbsp;3319<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nDescription<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u8bf7\u627e\u51fa\u4e00\u4e9b\u4e32\u7684\u6700\u957f\u2018\u6b63\/\u9006\u2018\u5b50\u4e32\uff0c\u4f7f\u5b83\u4e3a\u6240\u6709\u7684\u4e32\u7684\u5b50\u4e32\uff08\u5373\u4f7f\u662f\u9006\u5e8f\u4e5f\u8ba4\u4e3a\u5305\u542b\uff09.<\/div>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nInput<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u7b2c\u4e00\u884c\u4e3a\u6570\u636e\u6570t\uff0c(1 &lt;= t &lt;= 10),<\/div>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u5bf9\u6bcf\u7ec4\u6570\u636e\u800c\u8a00:\u7b2c\u4e00\u884c\u4e3a\u5b57\u7b26\u4e32\u4e2a\u6570<span style=\"font-family:'Times New Roman',Times,serif; font-size:16px\">&nbsp;n (1 &lt;= n &lt;= 100)\uff0c\u63a5\u4e0b\u6765n\u884c\u4e3a\u5b57\u7b26\u4e32\uff08\u957f\u5ea6\u4e0d\u8d85\u8fc7100\uff09 .<\/span><\/div>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nOutput<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n\u6bcf\u884c\u4e00\u4e2a\u6570\uff0c\u8868\u793a\u6700\u957f'\u6b63\/\u9006\u2018\u5b50\u4e32\u7684\u957f\u5ea6\u3002<\/div>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nSample Input<\/p>\n<pre class=\"sio\" style=\"font-family:'Courier New',Courier,monospace; font-size:12pt\">2\n3\nABCD\nBCDFF\nBRCD\n2\nrose\norchid<\/pre>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nSample Output<\/p>\n<pre class=\"sio\" style=\"font-family:'Courier New',Courier,monospace; font-size:12pt\">2\n2 <\/pre>\n<p class=\"pst\" style=\"text-align:left; font-size:18pt; font-weight:bold; color:blue\">\nSource<\/p>\n<div class=\"ptx\" lang=\"en-US\" style=\"font-family:'Times New Roman',Times,serif; font-size:12pt\">\n<a href=\"http:\/\/poj.org\/searchproblem?field=source&amp;key=Tehran+2002+Preliminary\" style=\"text-decoration:none\">Tehran 2002 Preliminary<\/a><\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-family:Simsun; font-size:14px\">\u8fd8\u662fKMP\uff0c\u5148\u5728\u7b2c\u4e00\u4e2a\u4e32\u4e2d\u679a\u4e3e\u4e32\uff0c\u4e4b\u540e\u8003\u5bdf\u5b83\u662f\u5426\u662f\u5176\u5b83\u4e32\u7684'\u6b63\/\u9006'\u5b50\u4e32\u3002<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><\/span><\/p>\n<pre name=\"code\" class=\"delphi\">Program P1226;\nconst\n   maxn=100;\n   maxt=10;\nvar\n   tt,n,m,i,j,k,ans:longint;\n   flag:boolean;\n   a:array[1..maxn] of string;\n   p:string;\n   next:array[1..maxn] of longint;\n\nfunction kmp(a,b:string):boolean;\nvar\n   i,j,n,m:longint;\nbegin\n   i:=1;j:=0;next[1]:=0;\n   n:=length(a); m:=length(b);\n   while (i&lt;m) do\n   begin\n      if (j=0) or (b[i]=b[j]) then\n      begin\n         inc(i);inc(j);\n         if (b[i]&lt;&gt;b[j]) then next[i]:=j else next[i]:=next[j];\n      end else j:=next[j];\n   end;\n\n   i:=0;j:=0;\n   while (i&lt;=n) and (j&lt;=m) do\n   begin\n      if (j=0) or (a[i]=b[j]) then\n      begin\n         inc(i);inc(j);\n      end else j:=next[j];\n   end;\n   if (j&gt;m) then exit(true);\n   exit(false);\nend;\nfunction ob_s(a:string):string;\nvar\n   i,j,n:longint;\nbegin\n\n   ob_s:=''; n:=length(a);\n   for i:=n downto 1 do ob_s:=ob_s+a[i];\nend;\nfunction compare(a,b:string):boolean;\nvar\n   n,m:longint;\nbegin\n   n:=length(a);m:=length(b);\n   if (n&lt;&gt;m) then exit(n&lt;m);\n   for i:=1 to n do\n      if a[i]&lt;&gt;b[i] then exit(a[i]&lt;b[i]);\n   exit(false);\nend;\n\n\nbegin\n   readln(tt);\n   while (tt&gt;0) do\n   begin\n      ans:=0;\n      readln(n);\n      for i:=1 to n do readln(a[i]);\n\n      for i:=1 to length(a[1]) do\n         for j:=i to length(a[1]) do\n         begin\n            p:=copy(a[1],i,j-i+1);\n            flag:=true;\n            for k:=2 to n do\n            begin\n               if not((kmp(a[k],p) or kmp(a[k],ob_s(p)))) then\n               begin\n                  flag:=false; break;\n               end;\n            end;\n            if flag and (length(p)&gt;ans) then ans:=length(p);\n\n\n         end;\n\n      writeln(ans);\n      dec(tt);\n   end;\nend.\n<\/pre>\n<\/p>\n<p><span style=\"font-family:Simsun; font-size:14px\"><br \/>\n<\/span><\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Language: Default Substrings Time Limit:&nbsp;1000MS &#038;n [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","footnotes":""},"categories":[3],"tags":[34],"class_list":["post-267","post","type-post","status-publish","format-standard","hentry","category-defaultcategory","tag-kmp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nike0good.com\/?p=267\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good\" \/>\n<meta property=\"og:description\" content=\"Language: Default Substrings Time Limit:&nbsp;1000MS &amp;n [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nike0good.com\/?p=267\" \/>\n<meta property=\"og:site_name\" content=\"nike0good\" \/>\n<meta property=\"article:published_time\" content=\"2012-11-15T07:21:00+00:00\" \/>\n<meta name=\"author\" content=\"nike0good\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"nike0good\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267\"},\"author\":{\"name\":\"nike0good\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"headline\":\"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09\",\"datePublished\":\"2012-11-15T07:21:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267\"},\"wordCount\":40,\"commentCount\":0,\"keywords\":[\"KMP\"],\"articleSection\":[\"DefaultCategory\"],\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=267#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267\",\"url\":\"https:\\\/\\\/nike0good.com\\\/?p=267\",\"name\":\"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\"},\"datePublished\":\"2012-11-15T07:21:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nike0good.com\\\/?p=267\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/?p=267#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/nike0good.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#website\",\"url\":\"https:\\\/\\\/nike0good.com\\\/\",\"name\":\"nike0good\",\"description\":\"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nike0good.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/nike0good.com\\\/#\\\/schema\\\/person\\\/4defa38da89de87e400861e73396baad\",\"name\":\"nike0good\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g\",\"caption\":\"nike0good\"},\"sameAs\":[\"https:\\\/\\\/nike0good.com\"],\"url\":\"https:\\\/\\\/nike0good.com\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nike0good.com\/?p=267","og_locale":"zh_CN","og_type":"article","og_title":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good","og_description":"Language: Default Substrings Time Limit:&nbsp;1000MS &n [&hellip;]","og_url":"https:\/\/nike0good.com\/?p=267","og_site_name":"nike0good","article_published_time":"2012-11-15T07:21:00+00:00","author":"nike0good","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"nike0good","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nike0good.com\/?p=267#article","isPartOf":{"@id":"https:\/\/nike0good.com\/?p=267"},"author":{"name":"nike0good","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"headline":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09","datePublished":"2012-11-15T07:21:00+00:00","mainEntityOfPage":{"@id":"https:\/\/nike0good.com\/?p=267"},"wordCount":40,"commentCount":0,"keywords":["KMP"],"articleSection":["DefaultCategory"],"inLanguage":"zh-Hans","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nike0good.com\/?p=267#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nike0good.com\/?p=267","url":"https:\/\/nike0good.com\/?p=267","name":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09 - nike0good","isPartOf":{"@id":"https:\/\/nike0good.com\/#website"},"datePublished":"2012-11-15T07:21:00+00:00","author":{"@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad"},"breadcrumb":{"@id":"https:\/\/nike0good.com\/?p=267#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nike0good.com\/?p=267"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/nike0good.com\/?p=267#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/nike0good.com\/"},{"@type":"ListItem","position":2,"name":"POJ 1226(\u6700\u957f\u516c\u5171\u5b50\u4e32\u542b\u9006\u5e8f\uff09"}]},{"@type":"WebSite","@id":"https:\/\/nike0good.com\/#website","url":"https:\/\/nike0good.com\/","name":"nike0good","description":"\u6709\u6240\u4f5c\u4e3a\u662f\u4eba\u751f\u7684\u6700\u9ad8\u5883\u754c","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nike0good.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/nike0good.com\/#\/schema\/person\/4defa38da89de87e400861e73396baad","name":"nike0good","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8e5fa08d5c367a1a6fb5ff13bb10ed5a331f981513256951290ae42322da6854?s=96&d=identicon&r=g","caption":"nike0good"},"sameAs":["https:\/\/nike0good.com"],"url":"https:\/\/nike0good.com\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=267"}],"version-history":[{"count":0,"href":"https:\/\/nike0good.com\/index.php?rest_route=\/wp\/v2\/posts\/267\/revisions"}],"wp:attachment":[{"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nike0good.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}