1 solutions
-
-1
#include #include #include #include using namespace std; char a[3000],b[3000]; int len1,len2,k; int f[3000][3000];
void init(){ len1=strlen(a+1);len2=strlen(b+1); for(int i=1;i<=len1;i++){ f[i][0]=f[i-1][0]+k; } for(int i=1;i<=len2;i++){ f[0][i]=f[0][i-1]+k; } }
int dis(char a,char b){ if(a==' '||b==' ')return k; return abs(a-b); }
int main(){ cin>>(a+1)>>(b+1)>>k; init(); for(int i=1;i<=len1;i++){ for(int j=1;j<=len2;j++){ f[i][j]=min(f[i-1][j]+k,min(f[i][j-1]+k,f[i-1][j-1]+abs((int)a[i]-(int)b[j]))); } } cout<<f[len1][len2]<<endl; return 0; }
- 1
Information
- ID
- 277
- Time
- 1000ms
- Memory
- 125MiB
- Difficulty
- 3
- Tags
- # Submissions
- 2
- Accepted
- 2
- Uploaded By