Strange road - like pressure DP

Title Description

Xiaoyu learned that an ancient civilization from the history books. This highly developed civilization in all aspects of transport is no exception. 
Archaeologists already know that this civilization has n cities in the heyday numbered 1..n. m road connections between these cities, roads each connecting two cities, such that the two residents may conveniently be between. 
There may be a number of road between a pair of cities. According to historical records, the civilization of the transport network to meet the two strange features. 
First, the digital civilization worship K, so for any road, which connects the two cities located respectively u and v, it must meet 1 <= | u - v | <= K. In addition, any city are connected to the road just even-numbered (0 is also considered an even number). 
However, because time is too long, specific transportation network we have not learned. 
Xiaoyu was curious how many possible connection methods between the n cities, so she turned to you.  
A large number of possible methods, you only need to output the digital-analog method 1,000,000,007.

100% data satisfies 1 <= n <= 30, 0 <= m <= 30, 1 <= K <= 8.   

 

Starter meaning of problems: n-m-point edges, satisfy the condition:

  1. Of each point is an even number.
  2. Each edge connected to vertex u, v number does not exceed the difference between K and no self-loop.

% Number Evaluating the value of 1,000,000,007.

Thinking

  Very God-like pressure of a $ DP $ title. Indicates that the state quantity of the difficulty. First, we analyze the range of data, we found that $ K <= 8 $, then it is clear that the state of compression of peacekeeping K about, we also think of a reason like the direct pressure of $ DP $.

  Then there is $ f [i] [j] [s] $ $ I $ represents the front points, and even the edges $ j, number ik-> state of point I $ $ s $, $ s $ then clearly It indicates the degree of parity of these points.

  Then a happy start to push. Consider adding an edge state transitions. Then after, there is no then the. . . . . . (I do this question will stop here)

  How plus side? To $ i $ as an endpoint, another one? It is clear that this state is not sufficient to meet the $ DP $ transfer, we need to add a dimension to indicate the current $ i $ the point at which even the edges. And because the difference between the vertex numbers $ <= k $, $ i we need only consider the interval [ik, i-1] $ side it is connected. Then there is $ f [i] [j] [s] [l] denotes the i-th point before, and even the edges j, [IK, i] is the state of s, i and the processing of the current point of ik + l $ even between the edges.

  Transfer is not particularly difficult (Table brush used here):

  1. $ I and i-k + l discontinuous rim, there is f [i] [j] [s] [l + 1] + = f [i] [j] [s] [l] $
  2. $ I and i-k + l $ connected side, there $ f [i] [j + 1] [s $ $ \ oplus $ $ 1 << k $ $ \ oplus $ $ 1 << l] [l] + = f [i] [j] [s] [l] $
  3. Consider adding a point, you must have: Number of points for the $ ik $ degree is even, $ [ik, i-1] $ interval point and i have all been transferred

  The answer is $ f [n] [m] [0] [k] $ $ front connection points of n-$ $ $ m edges, and when the process is $ nk + k = n $, $ i.e. [NK , n-1] $ processed in all cases.

code

#include <bits / STDC ++ H.>
 the using  namespace STD;
 const  int P = 1000000007 ;
 const  int S = . 1 << . 9 ;
 int F [ 35 ] [ 35 ] [S] [ 35 ];
 int n-, m, K; 
 
int main () 
{ 
    Scanf ( " % D% D% D " , & n-, & m, & K); 
    F [ 2 ] [ 0 ] [ 0 ] [ 0 ] = . 1 ; // initialize, 1 and 2 are not connected side is also a program 
    for (int i=2;i<=n;i++)
    for(int j=0;j<=m;j++)
    for(int s=0;s<(1<<k+1);s++)//枚举状态 
    {
        for(int l=0;l<k;l++)//枚举i-k+l
        {
            f[i][j][s][l+1]+=f[i][j][s][l]%=p;//不连边 
            if(i-k+l>0&&j<m)f[i][j+1][s^(1<<l)^(. 1 << K)] [L] + = F [I] [J] [S] [L]% = P; // even edge 
        }
         IF (! (S & . 1 )) F [I + . 1 ] [J] [ >> S . 1 ] [ 0 ] = F + [I] [J] [S] [K] =% P; // the ik omitted, was added. 1 + I 
    } 
    COUT << F [n-] [m] [ 0 ] [K]; 
}

Guess you like

Origin www.cnblogs.com/THRANDUil/p/11588372.html