利用PHP怎么求解最长的公共子串-创新互联
利用PHP怎么求解最长的公共子串?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

LCS经典算法php版本
= 0; $i--){
for ($j = $substringLength3 - 1; $j >= 0; $j--){
if ($x[$i] == $y[$j])
$opt[$i][$j] = $opt[$i + 1][$j + 1] + 1;
else
$opt[$i][$j] = max($opt[$i + 1][$j], $opt[$i][$j + 1]);
}
}
echo "substring1:".$x."\r\n";
echo "substring2:".$y."\r\n";
echo "LCS:";
$i = 0;
$j = 0;
while ($i < $substringLength2 && $j < $substringLength3){
if ($x[$i] == $y[$j]){
echo $x[$i];
$i++;
$j++;
} else if ($opt[$i + 1][$j] >= $opt[$i][$j + 1])
$i++;
else
$j++;
}
$endTime = microtime(true);
echo "\r\n";
echo "Totle time is " . ($endTime - $startTime) . " s";
}
public static function GetRandomStrings($length){
$buffer = "abcdefghijklmnopqrstuvwxyz";
$str="";
for($i=0;$i<$length;$i++){
$random=rand(0,strlen($buffer)-1);
$str.=$buffer[$random];
}
return $str;
}
}
LCS::main();
?>运行结果:
substring1:cgqtdaacneftabsxvmlb substring2:suwjwwakzzhghbsmnksg LCS:absm Totle time is 0.000648975372314 s
看完上述内容,你们掌握利用PHP怎么求解最长的公共子串的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!
本文名称:利用PHP怎么求解最长的公共子串-创新互联
文章分享:http://www.jxjierui.cn/article/cdiijg.html


咨询
建站咨询
