Base dice
In old age, the gambling ATM is infatuated with the base dice, that is, putting the dice on the top of the other. It cannot be twisted and twisted to form a square column.
After a long period of observation, ATM has discovered the mystery of the stable dice: some numbers are mutually exclusive!
Let's regulate the dice first: the opposite of 1 is 4, the opposite of 2 is 5, and the opposite of 3 is 6.
Assuming that M groups are mutually exclusive, and the two digits in each group are closely tied together, the dice cannot be stabilized. The ATM wants to calculate how many different possible base dice methods are available.
The two dice have the same method. If and only when the two dice have the same orientation as the number corresponding to the height.
Because the number of solutions may be too large, please output the result of MOD 10 ^ 9 + 7.
Don't underestimate the number of dice in the ATM ~
"Input format 」
The first line has two integers, n m.
N indicates the number of dice.
In the next m row, each row has two integers, A and B, indicating that a and B cannot stay together.
"Output format 」
The number of rows indicates the result of the 10 ^ 9 + 7 modulus of the answer.
「 Example input 」
2 1
1 2
「 Sample output 」
544
「 Data Scope 」
For 30% of data: n <= 5
For 60% of data: n <= 100
For 100% of data: 0 <n <= 10 ^ 9, m <= 36
Resource conventions:
Peak memory consumption (including virtual machines) <256 m
CPU consumption <2000 ms
Please output strictly as required. Do not print anything that is similar to "Please input.
All codes are stored in the same source file. After debugging is successful, copy and submit the source code.
Note: Do not use the package statement. Do not use the features of jdk1.7 or later.
Note: The main class name must be "Main"; otherwise, it will be processed as invalid code.
Solution: DP problem, but only part of data can be used. Put it on hold.
Import Java. math. biginteger; import Java. util. optional; public class main {public static final int mod = 1000000007; public static int init [] = {-1, 4, 5, 6, 1, 2, 3 }; // public static Boolean conflict [] [] = new Boolean [7] [7]; // public static void main (string [] ARGs) Conflict) {pipeline SC = new pipeline (system. in); int n = SC. nextint (); int M = SC. nextint (); For (INT I = 0; I <m; I ++) {int A = SC. nextint (); Int B = SC. nextint (); Conflict [A] [B] = conflict [B] [a] = true;} // DP [I] [J, I have a number of dice with J at the top and a rolling DP is used. Otherwise, biginteger DP [] [] = new biginteger [2] [7] is exceeded. int e = 0; For (INT I = 1; I <7; I ++) DP [E] [I] = biginteger. one; For (INT I = 2; I <= N; I ++) {e = 1-E; For (Int J = 1; j <7; j ++) {DP [E] [J] = biginteger. zero; For (int K = 1; k <7; k ++) {If (! Conflict [init [J] [k]) DP [E] [J] = DP [E] [J]. add (DP [1-e] [k]). moD (New biginteger (mod + "") ;}} biginteger sum = biginteger. zero; For (INT I = 1; I <7; I ++) {sum = sum. add (DP [E] [I]). moD (New biginteger (mod + "");} system. out. println (sum. multiply (quickpow (4, N )). moD (New biginteger (mod + "");} // Fast Power Static biginteger quickpow (int n, int m) {biginteger n1 = new biginteger (n + ""); biginteger T = biginteger. one; while (M> 0) {If (M & 1) = 1) t = T. multiply (N1 ). moD (New biginteger (mod + ""); n1 = n1.multiply (N1 ). moD (New biginteger (mod + ""); m >>= 1 ;}return t ;}}
Base dice-question Solution