1 条题解

  • 1
    @ 2025-11-2 18:45:21

    第一发

    #include <bits/stdc++.h>
    #define endl '\n'
    using namespace std;
    const int N=2e3+5,INF=0x3f3f3f3f,MOD=1e9+7;
    const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
    typedef long long LL;
    string a,b;
    int k,lena,lenb,dp[N][N];
    int main(){
    	ios::sync_with_stdio(false);
    	cin.tie(nullptr);cout.tie(nullptr);
    	cin>>a>>b>>k;
    	lena = a.size(),lenb = b.size();
    	a = " "+a,b = " "+b;
    	for(int i=1;i<=lena;i++)dp[i][0] = i*k;
    	for(int j=1;j<=lenb;j++)dp[0][j] = j*k;
    	for(int i=1;i<=lena;i++)
    		for(int j=1;j<=lenb;j++)
    			dp[i][j] = min({dp[i-1][j-1]+abs(a[i]-b[j]),dp[i-1][j]+k,dp[i][j-1]+k});
    	cout<<dp[lena][lenb];
    	return 0;
    }
    
    

    信息

    ID
    1436
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    递交数
    52
    已通过
    20
    上传者