Insufficient Disk Space
Time limit1sMemory limit128 MB
Given files to delete and files to keep, find the minimum number of rm commands (exact or prefix wildcard) to remove all deletable files while keeping the rest.
Problem
Yeonsu is running out of hard-disk space, so he wants to delete unnecessary files to free up room.
All files live in a single directory, and Yeonsu deletes them from that directory using the Linux rm command. The rm command can be used in the following two forms:
rm filename— deletes exactly the single file whose name isfilename.rm string*— deletes, in one shot, every file whose name equalsstringor begins withstring. The wildcard*may appear only at the very end of the string. (For example, you cannot write something likerm *.txt.) Ifstringis empty,rm *deletes every file in the directory.
You are given a set of files that must be deleted and a set of files that must never be deleted. Find the minimum number of rm commands needed to delete all of the files that must be deleted while deleting none of the files that must not be deleted.
Input
The first line contains the number of test cases T. Each test case has the following format:
- The first line contains
N1, the number of files that must be deleted (1 ≤ N1 ≤ 1000). - The next
N1lines each contain one name of a file that must be deleted. - The next line contains
N2, the number of files that must not be deleted (0 ≤ N2 ≤ 1000). - The next
N2lines each contain one name of a file that must not be deleted.
Every file name has length between 1 and 20 and consists only of uppercase and lowercase English letters, digits, and dots (.). Within a single test case, all file names are distinct.
Output
For each test case, print the minimum required number of rm commands on its own line.
Hint
In the first test case, the files that must be deleted can be removed exactly using the following 8 commands:
rm BAPC.*, rm filt*, rm filename*, rm clean, rm cleanup.IN1, rm cleanup.IN2, rm cleanup.out, rm p*