Test instructions
If there are 2 permutations, a, B, the definition sequence C is:
C[i] = (A[i] + b[i]-2)% n + 1
However, obviously C is not necessarily an arrangement
Now, give the length of the arrangement n (1 <= n <= 16)
Ask how many kinds of combinations of A/b are arranged, so that the resulting c is also an arrangement
Combination of permutations a = X,b = Y with a combination of permutations a = Y,b = X is 2 different schemes
Ideas:
There are 3 permutations, assuming A is 1,2,3,...,n
And then it turns out * n! is the answer.
Consider the pressure DP
J is a 16-bit number, which is the number of the n number of records B
F (i,j) indicates that a uses the 1~i,b number of J Records, the number of the first I of the generated C
Init:f (0,0) = 1
ans = f (n, (1<<n)-1) * n! transfer equation:
There's no way to move, because we still have to know what's in C and what counts.
If you add another dimension to the status of C, the array cannot be opened.
Then it's written in the form of a search.
DFS (U,V,W) indicates that a uses the 1~u,b,c for each of the V,W records.
if (U = = n + 1) ans++;
But that's going to time out, 1 <= n <= 16, so small, so it's a direct table.
Code:
//File Name:cf285D.cpp//Author:long//Mail: [email protected]//Created time:2016 July 09 Saturday 16:44 05 Seconds#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#defineLL Long Longusing namespacestd;Const intMOD = (int) 1e9 +7; LL Ans,n; LL jie[ -];intres[ -] = {0,1,0, -,0,1800,0,670320,0,734832000,0,890786230,0,695720788,0,150347555,0};voidinit () {jie[0] =1; for(intI=1;i< -; i++) Jie[i]= i * jie[i-1] %MOD; //ans = 0; //DFS (1,0,0);}voidDfsintAintBintc) { if(A = = n +1) {ans++; if(Ans >=MOD) ans-=MOD; return ; } intv; for(intI=0; i<n;i++){ if(((1<<i) & B) = =0) {v= (i + A-1) %N; if(((1<<V) & c) = =0) DFS (a+1+b[ (1<<i), c| (1<<v)); } }}intMain () {init (); while(~SCANF ("%d",&N)) {printf ("%d\n", Res[n]); } return 0;}
cf285 D. Permutation Sum-like pressure Dfs hit table