poj3356 dp

时间:2024-12-08 00:03:50
 //Accepted    4100 KB    0 ms
 //类似poj1080
 //dp[i][j]表示s1用前i个,s2用前j个的最少匹配步数
 //dp[i][j]=min(dp[i][j-1]+1,dp[i-1][j-1](s1[i-1]==s2[j-1])时 or dp[i-1][j-1]+1 (s1[i-1]!=s2[j-1]时))
 //注意初始化条件
 //dp[i][0]=inf;
 //dp[0][i]=i;
 //dp[0][0]=0;
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 using namespace std;
 ;
 ;
 char s1[imax_n];
 int n1;
 char s2[imax_n];
 int n2;
 int dp[imax_n][imax_n];
 void Dp()
 {
     ;i<=n1;i++)
     dp[i][]=inf;
     ;i<=n2;i++)
     dp[][i]=i;
     dp[][]=;
     ;i<=n1;i++)
     {
         ;j<=n2;j++)
         {
             ]==s2[j-])
             dp[i][j]=dp[i-][j-];
             else
             dp[i][j]=dp[i-][j-]+;
             ]+)
             dp[i][j]=dp[i][j-]+;
         }
     }
     printf("%d\n",dp[n1][n2]);
 }
 int main()
 {
     while (scanf("%d%s%d%s",&n1,s1,&n2,s2)!=EOF)
     {
         Dp();
     }
     ;
 }