-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminCostToMake2StringsEqual.cpp
More file actions
60 lines (46 loc) · 1.29 KB
/
minCostToMake2StringsEqual.cpp
File metadata and controls
60 lines (46 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
// } Driver Code Ends
class Solution{
public:
int findMinCost(string X, string Y, int costX, int costY)
{
int m=X.size(),n=Y.size();
int dp[m+1][n+1];
for(int i=0;i<=m;i++)
{
for(int j=0;j<=n;j++)
{
if(i==0 || j==0)
dp[i][j]=0;
else if(X[i-1]==Y[j-1])
dp[i][j]=dp[i-1][j-1]+1;
else
dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
}
}
int temp=dp[m][n];
int res=(m-temp)*costX+(n-temp)*costY;
}
};
// { Driver Code Starts.
int main()
{
//Given two strings X and Y, and two values costX and costY, the task is to find the minimum cost required to make the given two strings identical.
//You can delete characters from both the strings. The cost of deleting a character from string X is costX and from Y is costY.
//The cost of removing all characters from a string is the same.
int t;
cin >> t;
while (t--)
{
string x, y;
cin >> x >> y;
int costX, costY;
cin >> costX >> costY;
Solution ob;
cout << ob.findMinCost(x, y, costX, costY);
cout << "\n";
}
return 0;
}
// } Driver Code Ends