資源簡(jiǎn)介
對(duì)于給定的字符串A和B,給定其字串的內(nèi)容和空格相對(duì)字符的距離,使用動(dòng)態(tài)規(guī)劃算法求解兩字符串的擴(kuò)展距離。
代碼片段和文件信息
#include?
#include?
#define?MAXLEN?2000
#define?MAXINT?1000000
using?namespace?std;
int?Compute_Distance(char?str1char?str2)
{
return?(int)str1?>?(int)str2???(str1-str2):(str2-str1);
}
int?Compare_str(char?*str1char?*str2int?k)
{
int?len1len2ijtemp;
int?**val;
len1=strlen(str1);
len2=strlen(str2);
val=new?int?*?[len1+1];
for(i=0;i val[i]=new?int[len2+1];
val[0][0]=0;
for(i=0;i<=len1;i++)
for(j=0;j<=len2;j++)
if(i+j)
{
val[i][j]=MAXINT;
if((i*j)&&(temp=val[i-1][j-1]+Compute_Distance(str1[i-1]str2[j-1])) v
評(píng)論
共有 條評(píng)論