Write a program to maximize the cost of removing all occurrences of substrings “ab” and “ba”

Write a program to maximize the cost of removing all occurrences of substrings “ab” and “ba”.

Suppose a string S and integers P and Q, which denotes the cost of removal of substrings “ab” and “ba” respectively from S. So, the task is to find the maximum cost of removing all occurrences of substrings “ab” and “ba”. Take an example: How to solve this problem? This problem can be solved by using…
Read More