|
QueuingTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4348 Accepted Submission(s): 1925
Problem Description
Queues and Priority Queues are data structures which are known to most computer scientists. The Queue occurs often in our daily life. There are many people lined up at the lunch time.
Now we define that ‘f’ is short for female and ‘m’ is short for male. If the queue’s length is L, then there are 2 L numbers of queues. For example, if L = 2, then they are ff, mm, fm, mf . If there exists a subqueue as fmf or fff, we call it O-queue else it is a E-queue. Your task is to calculate the number of E-queues mod M with length L by writing a program.
Input
Input a length L (0 <= L <= 10
6) and M.
Output
Output K mod M(1 <= M <= 30) where K is the number of E-queues with length L.
Sample Input
Sample Output
Author
WhereIsHeroFrom
Source
思路:假设L长度的最后一位是m,那么只需要考虑前n-1位满足条件的个数,也就是f(n-1),如果最后一位不是m,再往前考虑一位,
那么最后三位可能是mmf,fmf,fff,mff,其中mmf,mff符合条件,mmf只需要前n-3位满足,mff只有mmff满足,即需要前n-4位满足,也
就是f(n) = f(n-1)+f(n-3)+f(n-4)。按照这样来建立构造矩阵。
|
HDU2604 Queuing(矩阵快速幂模板)
最新推荐文章于 2020-02-23 16:57:50 发布