Longest Common Subsequence Again

3.8

6 votes
Dynamic Programming, Algorithms, Medium, Dynamic programming
Problem

You are given two strings S, P and two integers, K1, K2. You have to find the length of the longest common subsequence after performing at-most K1 operations on string S and at-most K2 operations on string P. In one operation, you can change a character of the string to any alphabet.

INPUT FORMAT :
First line contains a string, S .
Second line contains a string, P.
Third line contains two space separated integers, K1 and K2 .

OUTPUT FORMAT :-
Print the length of the longest common subsequence after performing at-most K1 operations on string S and at-most K2 operations on string P.

CONSTRAINTS :-

  • 1|S|500 where S denotes the length of the string S
  • 1|P|500 where P denotes the length of the string P
  • 0K110
  • 0K210

  • Time Limit: 1
    Memory Limit: 256
    Source Limit:
    Explanation

    We can change first string S to dbcd and the Longest Common Subsequence will be 3 .

    Editor Image

    ?