Test instructions
Gambling San ATM in the old age infatuated with the dice, is the dice one base on the other top, not crooked, to base solutionkeys column body.
After a long observation, ATM found the secret of stabilizing the dice: Some of the number of the surface will be mutually exclusive!
Let's start by standardizing the dice: 1 opposite is 4,2 opposite is 5,3 opposite is 6.
If there is an M-group mutex, the two-digit face of each group clings to one another, and the dice cannot stabilize the base.
The ATM wants to calculate how many different possible ways to base the dice.
The two types of dice are the same, and the corresponding numbers of the dice corresponding to the height of the two methods are the same.
Because the number of scenarios may be too large, output modulo 10^9 + 7 results.
Do not underestimate the number of ATM dice Oh ~
"Input Format"
First row of two integers n m
n indicates the number of dice
The next m line, two integers a b per line, indicates that A and B numbers cannot be glued together.
"Output Format"
A row of a number that represents the result of the answer modulo 10^9 + 7.
"Sample Input"
2 1
1 2
"Sample Output"
544
"Data Range"
For 30% data: N <= 5
For 60% data: N <= 100
For 100% data: 0 < n <= 10^9, M <= 36
Resource contract:
Peak memory Consumption < 256M
CPU Consumption < 2000ms
Solution:
We open a a[6][6];
A[I][J] Indicates whether I point can be adjacent to J Point, if can be = 1, cannot be = 0;
This matrix is obtained with this input.
After writing the DP equation, you will find that a's column always has 3 offsets, because the shifted to the face is opposite, so in order to eliminate this offset, after the a matrix is obtained, move a to the left 3 columns.
Then it is the n-1 of the Matrix fast power.
The general difficulty should be to move left 3 columns.
No code~ here
Sixth session Blue Bridge Cup Java stack dice