62 条题解
-
0wllmh LV 10 @ 2009-10-26 12:47:32
ORZ地板
-
-12014-07-07 10:13:34@
#include<iostream>
#include<string>
using namespace std;
char a[2001],b[2001];
int k,k1,k2,f[2001][2001],n,m;
int main(void)
{
int i,j;
cin>>a>>b;
n=strlen(a); m=strlen(b);
cin>>k;
for (i=1;i<=n;i++) f[i][0]=i*k;
for (i=1;i<=m;i++) f[0][i]=i*k;
for (i=1;i<=n;i++)
for (j=1;j<=m;j++)
if (a[i]==b[j-1]) f[i][j]=f[i][j-1];
else
{
if (a[i]>b[j-1]) k1=a[i]-b[j-1]; else k1=b[j-1]-a[i];
k2=min(f[i-1][j]+k,f[i][j-1]+k);
f[i][j]=min(f[i][j-1]+k1,k2);
}
cout<<f[n][m];
}
哪里错了?