Sixth session Blue Bridge Cup Java stack dice

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.