首页 > 代码库 > ASC(1)E(矩阵快速幂+简单DP)
ASC(1)E(矩阵快速幂+简单DP)
Nice Patterns Strike Back
Problem Description
You might have noticed that there is the new fashion among rich people to have their yards tiled with black and white tiles, forming a pattern. The company Broken Tiles is well known as the best tiling company in our region. It provides the widest choices of nice patterns to tile your yard with. The pattern is nice if there is no square of size 2 × 2, such that all tiles in it have the same color. So patterns on the figure 1 are nice, while patterns on the figure 2 are not.
The president of the company wonders whether the variety of nice patterns he can provide to the clients is large enough. Thus he asks you to find out the number of nice patterns that can be used to tile the yard of size N × M . Now he is interested in the long term estimation, so he suggests N ≤ 10100. However, he does not like big numbers, so he asks you to find the answer modulo P .
Input
Output
Sample Input
2 2 5 3 3 23
Sample Output
4 0
ASC(1)E(矩阵快速幂+简单DP)