[5492] Luo Valley [PKUWC2018] random algorithm (like pressure DP)

Click here to see the problem surface

Generally meaning of the questions: seeking a graph with the maximum independent set of random algorithm: each time a random arrangement, the arrangement enumerated points from front to back, if the current point is added is still independent set point set, it will be added to the current point set point , the resulting set of points is the maximum independent set. Seeking the accuracy of randomized algorithms.

Foreword

\ (PKUWC \) the title is wonderful ah.

Topic is immortal, but after reading the solution to a problem is very simple, so I like this kind of thing can konjac do not think ah ......

Shaped pressure \ (the DP \)

Set \ (f_ {i, j} \) represents the set of points is currently considered \ (I \) , maximum independent set of \ (J \) program number.

Every time we do not enumerate a point set point \ (k \) collection points, located adjacent to \ (a_k \) .

Then, if we have to choose the point \ (k \) as an independent set point, then the adjacent point you can not choose your convenience, we directly \ (a_k \) counted considered the point.

That is, for the \ (f_ {i, j} \) and \ (K \) , we may be transferred to \ (I F_ {| K-2. 1} ^ {| a_k,. 1 + J} \) .

Note, this is the reason why \ (K-2. 1 ^ {} \) , because I used binary Dir \ (x-1 \) bits to represent the section \ (X \) if the number is selected.

Not difficult to find, according to our way of transfer, due to the \ (k \) is not centralized point, it was chosen as the point of focus points separate set point must not and \ (k \) adjacent to, or is selected as at that point the independence has been set point \ (K \) added to the set point, it will inevitably \ (J \) can be added \ (1 \) .

Then we consider this a step in the transfer, \ (k \) is certainly to be added directly to the point of focus, that is inevitable ranked first in the rest of the points, its position is fixed.

For those (K \) \ adjacent, not in the set of points \ (I \) points (ie: \ (a_k- (I \ & a_k) \) ), they can \ (K \) after any one of positions (consensus \ (n-g_i-1 \ ) position, where \ (G_i \) representative point set (I \) \ points, \ (1 \) representative point \ (K \) ) was added points set, so the number of programs for \ (A_ {-n-G_i. 1} ^ {-G_ {a_k- (I \ & a_k)}} \) .

Wherein, \ (A \) represents the number of permutations, \ (A_n ^ m = \ {n-FRAC!} {(Nm)!} \) ; \ (G_i \) represents the set of points \ (I \) number midpoint .

所以:\(f_{i|2^{k-1}|a_k,j+1}+=f_{i,j}\cdot A_{n-g_i-1}^{g_{a_k-(i\&a_k)}}\)

Since the determination of probability, we find that the program number, so the final answer is: \ (\ FRAC {F_ {2 ^ the n--1, w}} \ {the n-!}) , Which \ (w \) represents the largest independent the size of the set.

Code

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 20
#define X 998244353
#define A(x,y) (1LL*Fac[x]*IFac[(x)-(y)]%X)
using namespace std;
int n,m,a[N+5],f[1<<N][N+5],g[1<<N],Fac[N+5],IFac[N+5];
I int Qpow(RI x,RI y) {RI t=1;W(y) y&1&&(t=1LL*t*x%X),x=1LL*x*x%X,y>>=1;return t;}
int main()
{
    RI i,x,y;for(scanf("%d%d",&n,&m),i=1;i<=m;++i) scanf("%d%d",&x,&y),a[x]|=1<<y-1,a[y]|=1<<x-1;//读入,记录相邻点
    for(Fac[0]=i=1;i<=N;++i) Fac[i]=1LL*Fac[i-1]*i%X;//预处理阶乘
    for(IFac[N]=Qpow(Fac[N],X-2),i=N-1;~i;--i) IFac[i]=1LL*IFac[i+1]*(i+1)%X;//预处理阶乘逆元
    RI j,k,t=1<<n;for(i=0;i^t;++i) g[i]=g[i>>1]+(i&1);for(f[0][0]=1,i=0;i^t;++i)//枚举点集
    {
        for(j=0;j<=g[i];++j) for(k=1;k<=n;++k) !((i>>k-1)&1)&&//一定要选择不在点集中的点
            (f[i|(1<<k-1)|a[k]][j+1]=(1LL*f[i][j]*A(n-g[i]-1,g[a[k]-(i&a[k])])+f[i|(1<<k-1)|a[k]][j+1])%X);//转移
    }
    for(i=n;!f[t-1][i];--i);return printf("%d",1LL*f[t-1][i]*IFac[n]%X),0;//求最大独立集点数,然后输出答案
}

Guess you like

Origin www.cnblogs.com/chenxiaoran666/p/Luogu5492.html