#P8624. [蓝桥杯 2015 省 AB] 垒骰子

    ID: 7684 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP2015矩阵加速蓝桥杯省赛

[蓝桥杯 2015 省 AB] 垒骰子

Problem Description

In his later years, the gambling master atm became obsessed with stacking dice. This means placing one die on top of another. The stack must not be tilted, and must form a straight square pillar.

After long observation, atm discovered the secret of stable dice: some numbered faces repel each other when they touch!

First, we standardize the die: the face opposite 11 is 44, opposite 22 is 55, and opposite 33 is 66.

Suppose there are mm groups of repelling pairs. For each group, if the two faces with those numbers are in close contact, then the dice stack cannot be stable.

atm wants to compute how many different possible ways there are to stack the dice.

Two stacking methods are considered the same if and only if, at every height, the corresponding dice have the same orientation of the corresponding numbers.

Since the number of methods may be very large, output the result modulo 109+710^9+7.

Do not underestimate how many dice atm has.

Input Format

The first line contains two integers nn and mm.

nn is the number of dice.

The next mm lines each contain two integers aa and bb, meaning that faces numbered aa and bb cannot be in close contact.

Output Format

Output one integer, the answer modulo 109+710^9+7.

2 1
1 2

544

Hint

For 30%30\% of the testdata: n5n \le 5.

For 60%60\% of the testdata: n100n \le 100.

For 100%100\% of the testdata: 0<n109,m360 < n \le 10^9, m \le 36.

Time limit: 2 seconds. Memory limit: 256 MB.

Lanqiao Cup 2015 Provincial Contest AB Group, Problem I.

Translated by ChatGPT 5