Amusement Park
Time limit1sMemory limit128 MB
Count how many distinct longest common subsequences two lists of up to 10000 numbers share, modulo 1000000007.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Bajtazar and Bajtoni went to an amusement park. They have visited it many times and know all the attractions well, so each of them prepared in advance a list of favorite attractions they would like to ride in order. The two lists were different, so the friends decided to cross out some entries so that the lists become identical. While doing so, they do not want to change the original order within either list. In addition, they want the agreed plan to be as long as possible. How many different plans can they obtain this way?
Input
The first line contains two integers and (), the lengths of Bajtazar's and Bajtoni's lists. The next two lines contain the lists of attractions proposed by each of them. Each is a list of integers in the range separated by single spaces, of length and respectively. Each number identifies one attraction in the amusement park.
Output
On the first and only line of standard output, print a single integer. It should be the number of different longest amusement-park sightseeing plans the friends can create by crossing entries out of their proposed lists, taken modulo .