Topic Analysis:
Heard that the examination room can be $ O (4^n) $ of the violence of water over, difficult to make the question is the person is grandpa?
First think of an obvious $ O (n^2*2^n) $ of violent DP. The general DP is to consider which point has recently been added, and then delete the recursive after-pressure DP. Because the problem of the question of the way the question is reversed, the way of processing also in turn.
The $ f[n][s] $ representation currently has $ S $ for these points, expecting these points to be able to form a standalone set size of $ N $. The positive consideration selects which point, and all points that have a connection to the point are deleted within the collection, so that the new state found is $ f[n-1][p] $. We put the node in $ p $ in the concatenation with the points in $ S $ that are not in the $ P $. Written in language is $ f[n][s]+=f[n-1][p] * \binom{| s|-1}{| p|} * | p|! The time complexity becomes $ O (n^2*2^n) $ because each point of $ S $ needs to be shifted over. Although the run is not fast, but because of redundancy, a certain proportion of the examination room using the algorithm passed the problem.
Now consider optimizing it to $ O (n*2^n) $. Because the topic expects you to get a maximum independent set, we can find that the first dimension is not necessary. Because for a target state of $ S $, if we know the size of the maximum independent set corresponding to $ S $, then we must be running around this size. Now we use $ g[s] $ to represent the maximum independent set size corresponding to $ S $, then this is a universal group topic, enumerate the points and then ask Max to do it. For $ f[s] $, the maximum independent set size corresponding to $ S $ is calculated. First record $ g[s] $, and then look for a collection to delete a point after the change to $ g[s]-1 $ is what we want to transfer the scheme, the same with labeled stitching. Because we don't have the burden of the first dimension, the time complexity dips in order to $ O (n*2^n) $.
PS: I will finally use Letax mathematical formula.
Code:
1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intMAXN = -;5 Const intMoD =998244353;6 7 intn,m;8 intCONNECT[MAXN];9 intf[(1<< -)+5],g[(1<< -)+5],sz[(1<< -)+5];Ten intarr[(1<< -)+5],c[maxn][maxn],fac[ -]; One A intFast_pow (intNowintPW) { - if(PW = =1)returnNow ; - intz = Fast_pow (now,pw/2); thez = (1ll*z*z)%MoD; - if(PW &1) z = (1ll*z*now)%MoD; - returnZ; - } + - voidRead () { +scanf"%d%d",&n,&m); A for(intI=1; i<=m;i++){ at intU,v; scanf"%d%d",&u,&v); -Connect[u] |= (1<<v-1); -CONNECT[V] |= (1<<u-1); - } - for(intI=1; i<=n;i++) Connect[i] |= (1<<i-1); - } in - voidinit () { toc[0][0] =1; + for(intI=1; i<=n;i++){ -c[i][0] = C[i][i] =1; the for(intj=1; j<i;j++) C[i][j] = (c[i-1][j-1]+c[i-1][J])%MoD; * } $ for(intI=1;i< (1<<N); i++){Panax Notoginseng for(intj=0; j<n;j++)if((1<<J) &i) sz[i]++; - } thefac[0] =1; + for(intI=1; i<=n;i++) Fac[i] = (1ll*fac[i-1]*i)%MoD; A } the + voidDfsintNow ) { -Arr[now] =1; $ for(intI=1; i<=n;i++){ $ if(! ((1<<i-1) &now))Continue; - intp = Now-(now&connect[i]); - if(!Arr[p]) DFS (p); theG[now] = max (g[now],g[p]+1); - }Wuyi } the - voidDFS2 (intNow ) { WuArr[now] =1; - for(intI=1; i<=n;i++){ About if(! ((1<<i-1) &now))Continue; $ intKK = (now&connect[i]), p = now-KK; - if(g[p]! = g[now]-1)Continue; - if(!arr[p]) DFS2 (p); -f[now]+= ((1ll*c[sz[now]-1][sz[p]]*fac[sz[kk]-1])%mod) *f[p]%MoD; AF[now]%=MoD; + } the } - $ voidWork () { the init (); theg[0] =0; arr[0] =1; the for(intI=1;i< (1<<n); i++)if(!Arr[i]) DFS (i); thememset (arr,0,sizeof(arr)); -f[0] =1; arr[0] =1; inDFS2 ((1<<n)-1); the intAns = f[(1<<n)-1]; theAns = (1ll*fast_pow (fac[n],mod-2) *ans)%MoD; Aboutprintf"%d", ans); the } the the intMain () { + read (); - Work (); the return 0;Bayi}
LOJ2540 [PKUWC2018] Stochastic algorithm "pressure DP"