划分状态的依据是最后一步所进行的操作
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(bufferedReader.readLine());
char a[]=new char [n+10];
String pString=bufferedReader.readLine();
for(int i=1;i<=n;i++){
a[i]=pString.charAt(i-1);
}
int m=Integer.parseInt(bufferedReader.readLine());
char b[]=new char [m+10];
pString=bufferedReader.readLine();
for(int i=1;i<=m;i++){
b[i]=pString.charAt(i-1);
}
int f[][]=new int [n+1][m+1];
//初始化
f[0][0]=0;
for(int i=1;i<=n;i++)f[i][0]=i;
for(int i=1;i<=m;i++)f[0][i]=i;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
f[i][j]=Math.min(f[i][j-1], f[i-1][j])+1;
if(a[i]==b[j]) f[i][j]=Math.min(f[i][j], f[i-1][j-1]);
else{
f[i][j]=Math.min(f[i][j], f[i-1][j-1]+1);
}
}
}
System.out.println(f[n][m]);
}
}