Problem Description
A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall.
In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue.

Input
There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above.

Output
The output contains one line for each data set, formatted as shown in the sample output.

Sample Input
4 6
cs123 mt42 cs456 cs789
mt42 F 0
cs123 S 0
cs456 S 2 cs123 mt42
cs789 B 1 cs456
3 6
math1 comp2 comp3
comp3 S 1 comp2
math1 S 0
comp2 F 1 math1
4 3
m10 m20 c33 c44
m10 B 0
m20 B 0
c33 B 0
c44 B 0
-1 -1

Sample Output
The minimum number of semesters required to graduate is 5.
The minimum number of semesters required to graduate is 4.
The minimum number of semesters required to graduate is 2.

Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 <= n <= 12, which is the number of courses in this data set and m, 2 <= m <= 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered ('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 <= p <= 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.

Problem Description A prospective CS student is investigating how many semesters it will take to graduate from a variety of different universities. Each university provides a list of required courses, their prerequisites, and when each course is offered. Given this information, determine the minimum number of semesters to graduate. Consider the following example. A student is required to take 4 courses, mt42, cs123, cs456, and cs789. mt42 is only offered in the fall semester and has no prerequisites. Similarly, cs123 is only offered in the spring semester and has no prerequisites. cs456 is only offered in the spring semester and has both cs123 and mt42 as prerequisites. Finally, cs789 is offered in both fall and spring and has cs456 as its only prerequisite. The shortest time to graduate is 5 semesters, by taking mt42 in the fall, cs123 in the next spring, cs456 the following spring (since it is not offered in the fall) and finally cs789 the following fall. For this problem, there are only two semesters, fall and spring. Always start counting semesters from the fall. In addition to the fall/spring scheduling issues, there is one slight complication. In order to keep the dormitories full, each university limits the number of courses that can be taken in any semester. This limit appears as part of the input data. The third example below illustrates this issue. Input There are one to twenty-five data sets, followed by a final line containing only the integers -1 -1. A data set starts with a line containing two positive integers n, 1 ≤ n ≤ 12, which is the number of courses in this data set and m, 2 ≤ m ≤ 6, which is the maximum number of courses that can be taken in any single semester. The next line contains the n course identifiers. Each is a 1-5 character string from the set {a-z, 0-9}. Following the course identifiers is the individual course information. This consists of n lines, one line for each course, containing the course identifier, semester offered('F'=Fall, 'S'=Spring, 'B'=Both semesters), the number of prerequisite courses, p, 0 ≤ p ≤ 5, and finally p prerequisite course identifiers. The first example data set below corresponds to the problem described above. Output The output contains one line for each data set, formatted as shown in the sample output. Sample Input 4 6 cs123 mt42 cs456 cs789 mt42 F 0 cs123 S 0 cs456 S 2 cs123 mt42 cs789 B 1 cs456 3 6 math1 comp2 comp3 comp3 S 1 comp2 math1 S 0 comp2 F 1 math1 4 3 m10 m20 c33 c44 m10 B 0 m20 B 0 c33 B 0 c44 B 0 -1 -1 Sample Output The minimum number of semesters required to graduate is 5. The minimum number of semesters required to graduate is 4. The minimum number of semesters required to graduate is 2.
GRE Words 是怎么实现的
Problem Description Recently George is preparing for the Graduate Record Examinations (GRE for short). Obviously the most important thing is reciting the words. Now George is working on a word list containing N words. He has so poor a memory that it is too hard for him to remember all of the words on the list. But he does find a way to help him to remember. He finds that if a sequence of words has a property that for all pairs of neighboring words, the previous one is a substring of the next one, then the sequence of words is easy to remember. So he decides to eliminate some words from the word list first to make the list easier for him. Meantime, he doesn't want to miss the important words. He gives each word an importance, which is represented by an integer ranging from -1000 to 1000, then he wants to know which words to eliminate to maximize the sum of the importance of remaining words. Negative importance just means that George thought it useless and is a waste of time to recite the word. Note that although he can eliminate any number of words from the word list, he can never change the order between words. In another word, the order of words appeared on the word list is consistent with the order in the input. In addition, a word may have different meanings, so it can appear on the list more than once, and it may have different importance in each occurrence. Input The first line contains an integer T(1 <= T <= 50), indicating the number of test cases. Each test case contains several lines. The first line contains an integer N(1 <= N <= 2 * 104), indicating the number of words. Then N lines follows, each contains a string Si and an integer Wi, representing the word and its importance. Si contains only lowercase letters. You can assume that the total length of all words will not exceeded 3 * 105. Output For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is the largest importance of the remaining sequence of words. Sample Input 1 5 a 1 ab 2 abb 3 baba 5 abbab 8 Sample Output Case #1: 14
GRE Words 单词的程序设计
Problem Description Recently George is preparing for the Graduate Record Examinations (GRE for short). Obviously the most important thing is reciting the words. Now George is working on a word list containing N words. He has so poor a memory that it is too hard for him to remember all of the words on the list. But he does find a way to help him to remember. He finds that if a sequence of words has a property that for all pairs of neighboring words, the previous one is a substring of the next one, then the sequence of words is easy to remember. So he decides to eliminate some words from the word list first to make the list easier for him. Meantime, he doesn't want to miss the important words. He gives each word an importance, which is represented by an integer ranging from -1000 to 1000, then he wants to know which words to eliminate to maximize the sum of the importance of remaining words. Negative importance just means that George thought it useless and is a waste of time to recite the word. Note that although he can eliminate any number of words from the word list, he can never change the order between words. In another word, the order of words appeared on the word list is consistent with the order in the input. In addition, a word may have different meanings, so it can appear on the list more than once, and it may have different importance in each occurrence. Input The first line contains an integer T(1 <= T <= 50), indicating the number of test cases. Each test case contains several lines. The first line contains an integer N(1 <= N <= 2 * 104), indicating the number of words. Then N lines follows, each contains a string Si and an integer Wi, representing the word and its importance. Si contains only lowercase letters. You can assume that the total length of all words will not exceeded 3 * 105. Output For each test case in the input, print one line: "Case #X: Y", where X is the test case number (starting with 1) and Y is the largest importance of the remaining sequence of words. Sample Input 1 5 a 1 ab 2 abb 3 baba 5 abbab 8 Sample Output Case #1: 14
Sokoban 完整性判断
Problem Description Soko-ban is a Japanese word for a warehouse worker, and the name of a classic computer game created in the 1980s. It is a one-player game with the following premise. A single worker is in an enclosed warehouse with one or more boxes. The goal is to move those boxes to a set of target locations, with the number of target locations equalling the number of boxes. The player indicates a direction of motion for the worker using the arrow keys (up, down, left, right), according to the following rules. 1.If the indicated direction of motion for the worker leads to an empty location (i.e., one that does not have a box or wall), the worker advances by one step in that direction. 2.If the indicated direction of motion would cause the worker to move into a box, and the location on the other side of the box is empty, then both the worker and the box move one spot in that direction (i.e., the worker pushes the box). 3.If the indicated direction of motion for a move would cause the worker to move into a wall, or to move into a box that has another box or a wall on its opposite side, then no motion takes place for that keystroke. The goal is to simultaneously have all boxes on the target locations. In that case, the player is successful (and as a formality, all further keystrokes will be ignored). The game has been studied by computer scientists (in fact, one graduate student wrote his entire Ph.D. dissertation about the analysis of sokoban). Unfortunately, it turns out that finding a solution is very difficult in general, as it is both NP-hard and PSPACE-complete. Therefore, your goal will be a simpler task: simulating the progress of a game based upon a player's sequence of keystrokes. For the sake of input and output, we describe the state of a game using the following symbols: For example, the initial configuration diagrammed at the beginning of this problem appears as the first input case below. Input Each game begins with a line containing integers R and C, where 4 ≤ R ≤ 15 represents the number of rows, and 4 ≤ C ≤ 15 represents the number of columns. Next will be R lines representing the R rows from top to bottom, with each line having precisely C characters, from left-to-right. Finally, there is a line containing at most 50 characters describing the player's sequence of keystrokes, using the symbols U, D, L, and R respectively for up, down, left, and right. You must read that entire sequence from the input, even though a particular game might end successfully prior to the end of the sequence. The data set ends with the line 0 0. We will guarantee that each game has precisely one worker, an equal number of boxes and locations, at least one initially misplaced box, and an outermost boundary consisting entirely of walls. Output For each game, you should first output a line identifying the game number, beginning at 1, and either the word complete or incomplete, designating whether or not the player successfully completed that game. Following that should be a representation of the final board configuration. Sample Input 8 9 ######### #...#...# #..bb.b.# #...#w#.# #...#b#.# #...++++# #...#..## ######### ULRURDDDUULLDDD 6 7 ####### #..#### #.+.+.# #.bb#w# ##....# ####### DLLUDLULUURDRDDLUDRR 0 0 Sample Output Game 1: incomplete ######### #...#...# #..bb...# #...#.#.# #...#.#.# #...+W+B# #...#b.## ######### Game 2: complete ####### #..#### #.B.B.# #.w.#.# ##....# #######
Sokoban 的问题
Problem Description Soko-ban is a Japanese word for a warehouse worker, and the name of a classic computer game created in the 1980s. It is a one-player game with the following premise. A single worker is in an enclosed warehouse with one or more boxes. The goal is to move those boxes to a set of target locations, with the number of target locations equalling the number of boxes. The player indicates a direction of motion for the worker using the arrow keys (up, down, left, right), according to the following rules. 1.If the indicated direction of motion for the worker leads to an empty location (i.e., one that does not have a box or wall), the worker advances by one step in that direction. 2.If the indicated direction of motion would cause the worker to move into a box, and the location on the other side of the box is empty, then both the worker and the box move one spot in that direction (i.e., the worker pushes the box). 3.If the indicated direction of motion for a move would cause the worker to move into a wall, or to move into a box that has another box or a wall on its opposite side, then no motion takes place for that keystroke. The goal is to simultaneously have all boxes on the target locations. In that case, the player is successful (and as a formality, all further keystrokes will be ignored). The game has been studied by computer scientists (in fact, one graduate student wrote his entire Ph.D. dissertation about the analysis of sokoban). Unfortunately, it turns out that finding a solution is very difficult in general, as it is both NP-hard and PSPACE-complete. Therefore, your goal will be a simpler task: simulating the progress of a game based upon a player's sequence of keystrokes. For the sake of input and output, we describe the state of a game using the following symbols: For example, the initial configuration diagrammed at the beginning of this problem appears as the first input case below. Input Each game begins with a line containing integers R and C, where 4 ≤ R ≤ 15 represents the number of rows, and 4 ≤ C ≤ 15 represents the number of columns. Next will be R lines representing the R rows from top to bottom, with each line having precisely C characters, from left-to-right. Finally, there is a line containing at most 50 characters describing the player's sequence of keystrokes, using the symbols U, D, L, and R respectively for up, down, left, and right. You must read that entire sequence from the input, even though a particular game might end successfully prior to the end of the sequence. The data set ends with the line 0 0. We will guarantee that each game has precisely one worker, an equal number of boxes and locations, at least one initially misplaced box, and an outermost boundary consisting entirely of walls. Output For each game, you should first output a line identifying the game number, beginning at 1, and either the word complete or incomplete, designating whether or not the player successfully completed that game. Following that should be a representation of the final board configuration. Sample Input 8 9 ######### #...#...# #..bb.b.# #...#w#.# #...#b#.# #...++++# #...#..## ######### ULRURDDDUULLDDD 6 7 ####### #..#### #.+.+.# #.bb#w# ##....# ####### DLLUDLULUURDRDDLUDRR 0 0 Sample Output Game 1: incomplete ######### #...#...# #..bb...# #...#.#.# #...#.#.# #...+W+B# #...#b.## ######### Game 2: complete ####### #..#### #.B.B.# #.w.#.# ##....# #######

Problem Description Li Zhixiang have already been in “Friendship” ocean-going freighter for three months. The excitement has gradually disappeared. He stands on the board, holding the railing and watching the dazzling ocean in the sun silently. Day after day, the same scenery is monotonous and tasteless, even the merry seagulls following the freighter cannot arouse his interest. Hearing the footsteps behind, he turns back to see the old captain is coming towards him. The captain has understood his idea, however, he starts a new topic with the young man. “Do you know how far our voyage is?” The captain asks. Li Zhixiang feels ashamed because he can not answer. Then the captain says with a smile, “5050 miles. Do you still remember the story of 5050?” This time the young man really blushes. The old captain continues saying:” You definitely know the story of 5050. When the German mathematician, “the prince of mathematicians”, Gauss was 10 years old …” Young man remembers this story and goes on to tell, “ When Gauss was 10 years old, he could add a list of integers from 1 to 100 in a few seconds, which shocked the teachers.” The old captain adds, “Gauss has many other stories like this. When he entered the university at the age of 17, he was able to construct heptadecagon by compass and straightedge. His university teachers were also impressed by his ability. Not only could college graduate students fail to do it, but also they felt hard to understand Gauss’s constructing process.” At this time, vice-captain greets the old captain. The old captain says to Li Zhixiang: “Come over to my office tonight, let’s continue the conversation.” It is still calm and tranquil in the evening. The freighter travels smoothly on the sea in the silver moonlight. The captain tells the young man the following words. Among the mathematicians through the ages, there are three greatest mathematicians: Archimedes, Newton and Gauss. Most of Gauss’s mathematical achievements are difficult to understand. Nevertheless, there are some comparatively easy. For instance, when it comes to solving multivariate system of linear equations, there is a solution called “Gauss Elimination”. In the navigation business, many problems can be solved by “Gauss elimination”. If you are interested in it, I will show you a simple question. Try it.” Input There are several test cases. In the first line of each case, a number n indicates that there are n equations. The following n lines, each line has n+1 numbers, ai1,ai2,ai3…..ain, bi(1<= i <=n), these numbers indicate the coefficients of systems of the equations. ai1*x1+ai2*x2+......ain*xn=bi. Input is terminated by the end of file. Output For each given systems of equations, if there are solutions, output n solutions in the order of appearance in the equations（n<=100）, each solution number is in one line. If solution is not integer, show it in fraction. If no solution, output “No solution.” Leave a blank line after each case. Sample Input 2 1000000000000000000000000 1000000000000000000000000 1000000000000000000000000 -1000000000000000000000000 1000000000000000000000000 0 1 0 4 Sample Output 1/2 1/2 No solution.
Ride to School
Description Many graduate students of Peking University are living in Wanliu Campus, which is 4.5 kilometers from the main campus – Yanyuan. Students in Wanliu have to either take a bus or ride a bike to go to school. Due to the bad traffic in Beijing, many students choose to ride a bike. We may assume that all the students except "Charley" ride from Wanliu to Yanyuan at a fixed speed. Charley is a student with a different riding habit – he always tries to follow another rider to avoid riding alone. When Charley gets to the gate of Wanliu, he will look for someone who is setting off to Yanyuan. If he finds someone, he will follow that rider, or if not, he will wait for someone to follow. On the way from Wanliu to Yanyuan, at any time if a faster student surpassed Charley, he will leave the rider he is following and speed up to follow the faster one. We assume the time that Charley gets to the gate of Wanliu is zero. Given the set off time and speed of the other students, your task is to give the time when Charley arrives at Yanyuan. Input There are several test cases. The first line of each case is N (1 <= N <= 10000) representing the number of riders (excluding Charley). N = 0 ends the input. The following N lines are information of N different riders, in such format: Vi [TAB] Ti Vi is a positive integer <= 40, indicating the speed of the i-th rider (kph, kilometers per hour). Ti is the set off time of the i-th rider, which is an integer and counted in seconds. In any case it is assured that there always exists a nonnegative Ti. Output Output one line for each case: the arrival time of Charley. Round up (ceiling) the value when dealing with a fraction. Sample Input 4 20 0 25 -155 27 190 30 240 2 21 0 22 34 0 Sample Output 780 771

Java学习的正确打开方式

linux系列之常用运维命令整理笔录

python 简易微信实现（注册登录+数据库存储+聊天+GUI+文件传输）
socket+tkinter详解+简易微信实现 历经多天的努力，查阅了许多大佬的博客后终于实现了一个简易的微信O(∩_∩)O~~ 简易数据库的实现 使用pands+CSV实现数据库框架搭建 import socket import threading from pandas import * import pymysql import csv # 创建DataFrame对象 # 存储用户数据的表（...

Python十大装B语法
Python 是一种代表简单思想的语言，其语法相对简单，很容易上手。不过，如果就此小视 Python 语法的精妙和深邃，那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点，并附上详细的实例代码。如能在实战中融会贯通、灵活使用，必将使代码更为精炼、高效，同时也会极大提升代码B格，使之看上去更老练，读起来更优雅。

2019年11月中国大陆编程语言排行榜
2019年11月2日，我统计了某招聘网站，获得有效程序员招聘数据9万条。针对招聘信息，提取编程语言关键字，并统计如下： 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...

《奇巧淫技》系列-python！！每天早上八点自动发送天气预报邮件到QQ邮箱

JavaScript 为什么能活到现在？

Nginx 原理和架构
Nginx 是一个免费的，开源的，高性能的 HTTP 服务器和反向代理，以及 IMAP / POP3 代理服务器。Nginx 以其高性能，稳定性，丰富的功能，简单的配置和低资源消耗而闻名。 Nginx 的整体架构 Nginx 里有一个 master 进程和多个 worker 进程。master 进程并不处理网络请求，主要负责调度工作进程：加载配置、启动工作进程及非停升级。worker 进程负责处...

Python 编程开发 实用经验和技巧
Python是一门很灵活的语言，也有很多实用的方法，有时候实现一个功能可以用多种方法实现，我这里总结了一些常用的方法和技巧，包括小数保留指定位小数、判断变量的数据类型、类方法@classmethod、制表符中文对齐、遍历字典、datetime.timedelta的使用等，会持续更新......

“狗屁不通文章生成器”登顶GitHub热榜，分分钟写出万字形式主义大作

《程序人生》系列-这个程序员只用了20行代码就拿了冠军

11月8日，由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办，科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。 　　区块链技术被认为是继蒸汽机、电力、互联网之后，下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力，电力解决了人类基本的生活需求，互联网彻底改变了信息传递的方式，区块链作为构造信任的技术有重要的价值。 　　1...
Python 植物大战僵尸代码实现(2):植物卡片选择和种植

shell脚本基础
shell简介：shell是一种脚本语言，可以使用逻辑判断、循环等语法，可以自定义函数，是系统命令的集合 文章目录shell脚本结构和执行方法shell脚本中date命令的用法 shell脚本结构和执行方法 1.shell脚本开头需要加#!/bin/bash 2.以#开头的行作为注释 3.脚本的名字以.sh结尾，用于区分这是一个shell脚本 4.执行方法有两种： 1）bash test.sh 2...