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, , . You have to find the length of the longest common subsequence after performing at-most operations on string S and at-most 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, and .

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

CONSTRAINTS :-

  • where S denotes the length of the string S
  • where P denotes the length of the string P

  • Sample Input
    abcd
    dbca
    1 0
    Sample Output
    3
    Time Limit: 1
    Memory Limit: 256
    Source Limit:
    Explanation

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

    Editor Image

    ?