Problem p03165 - Generation 1

Orig Description

Score : 100 points
Problem StatementYou are given strings s and t.
Find one longest string that is a subsequence of both s and t.
NotesA subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.
Constraints
s and t are strings consisting of lowercase English letters.
1 \leq |s|, |t| \leq 3000
InputInput is given from Standard Input in the following format:
s
t
OutputPrint one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.
Sample Input 1axyb
abyxb
Sample Output 1axb
The answer is axb or ayb; either will be accepted.
Sample Input 2aa
xayaz
Sample Output 2aa
Sample Input 3a
z
Sample Output 3
The answer is  (an empty string).
Sample Input 4abracadabra
avadakedavra
Sample Output 4aaadara

Extracted Specification

An integer \( M \) (1 ≤ \( M \) ≤ 3000), representing the length of the first string.
An integer \( N \) (1 ≤ \( N \) ≤ 3000), representing the length of the second string.
A string \( X \) of length \( M \), consisting of lowercase English letters.
A string \( Y \) of length \( N \), consisting of lowercase English letters.

### Example Input:

```
4
5
axyb
abyxb
```

### Function Signature:
Write a function f(M, N, X, Y) that takes in the input.
def f(M: int, N: int, X: str, Y: str): 
    ''' 
    M: an integer
    N: an integer
    X: a string
    Y: a string
    '''

Test Case Generator

Sure! To generate test cases for the problem statement efficiently, we can create a function that randomly generates strings `s` and `t` within the given constraints. Here's a Python function to do that:

```python
import random
import string

def tcgen():
    # Generate lengths for s and t within the given constraints
    len_s = random.randint(1, 3000)
    len_t = random.randint(1, 3000)
    
    # Generate random lowercase strings of the given lengths
    s = ''.join(random.choices(string.ascii_lowercase, k=len_s))
    t = ''.join(random.choices(string.ascii_lowercase, k=len_t))
    
    return s, t

# Example usage:
s, t = tcgen()
print(f"Generated Test Case:\ns = {s}\nt = {t}")
```

This code randomly generates two strings `s` and `t` consisting of lowercase English letters, with lengths between 1 and 3000 inclusive. The function `tcgen` returns these generated strings. You can use this function to generate multiple test cases for the problem.

Feel free to modify the function if you need specific patterns or edge cases. Here's a quick guide on generating some specific edge cases:

1. **Minimal Length Strings**: `len_s` and `len_t` set to 1.
2. **Maximal Length Strings**: `len_s` and `len_t` set to 3000.
3. **Strings With No Common Subsequences**: Generate strings with non-overlapping character sets.
4. **Identical Strings**: Set `s` equal to `t`.

The above function can be adjusted easily to cover these scenarios.

Extract Arguments

def extract_arguments(fh):
    s = fh.readline().strip()
    t = fh.readline().strip()
    return s, t