Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 09 January 2023 [19:54]
- */
- #include<bits/stdc++.h>
- using namespace std;
- char a[1010],b[1010];
- int dp[1010][1010];
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int c1,c2,c3; //c1 = cost of adding, c2 = cost of removing, c3 = cost of replacing
- cin >> a+1 >> b+1 >> c1 >> c2 >> c3;
- int n = strlen(a+1),m = strlen(b+1);
- for(int i=1;i<=n;i++) dp[i][0] = i;
- for(int j=1;j<=m;j++) dp[0][j] = j;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=m;j++){
- if(a[i] == b[j])
- dp[i][j] = dp[i-1][j-1];
- else
- dp[i][j] = min({dp[i-1][j]+c1,dp[i][j-1]+c2,dp[i-1][j-1]+c3});
- }
- }
- cout << dp[n][m] << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment