提交时间:2023-12-26 13:52:18

运行 ID: 117813

#include<bits/stdc++.h> using namespace std; char s1[1001],s2[1001]; int maxlen[1001][1001]; int main() { cin>>s1>>s2; int len1=strlen(s1),len2=strlen(s2),i,j; for(i=0;i<=len1;i++) maxlen[i][0]=0; for(j=0;j<=len2;j++) maxlen[0][j]=0; for(i=1;i<=len1;i++) for(j=1;j<=len2;j++) { if(s1[i-1]==s2[j-1]) maxlen[i][j]=maxlen[i-1][j-1]+1; else maxlen[i][j]=max(maxlen[i-1][j],maxlen[i][j-1]); } cout<<(len1+len2-2*maxlen[len1][len2]);