"PKUWC 2018" Stochastic algorithm (60-part-divided approach)

Source: Internet
Author: User

Tomorrow is CTSC Day 2 qwq, night knock on violence save the RP, decisive casually read a problem is to fight violence hhhhh

Before 50% O (3^n) Violence there is nothing to say, we set F[s][s] to have selected the points in the S set, and the maximum independent set of points in this set is the number of S scheme, and finally counted on the multiply n!  The inverse of the yuan just fine. (s must be a subset of s, so the complexity is 3^n)

Then the violence in the middle of the goose will only chain ....

First, if n is an odd number, then the maximum independent set may be all odd points, all of which we know the set of selected points to know what the independent set is, so you can directly O (2^N) DP ....

But the question is not so conscientious. 2333, the N of this point is even in the final data ....

Consider that if n is an even number of cases, the independent set can only be: all the odd points or all even points or ∑[i is even] <=i all the odd points and >i are all even points, so we first use and ask N is an odd number of the same method (the King James Maximum independent set is all odd points) to find out the For each even I, the maximum independent set is the answer to the odd point of the <=i, and then the convolution merges just fine, because the set of points behind all the even numbers can be seen as a set of all odd points in the opposite direction.

The combined number is also multiplied, because the order of the elements between the two sides is not determined,

#include <bits/stdc++.h> #define LL long longusing namespace Std;const int Maxn=300005,ha=998244353;inline int Add ( int &x,int y) {x+=y; if (X>=ha) X-=ha;} inline int ksm (int x,int y) {int an=1; y;y>>=1,x=x* (LL) x%ha) if (y&1) an=an* (ll) X%ha; return an;} Unordered_map<int,int> F[maxn];unordered_map<int,int>:: Iterator It;int N,ci[35],m,uu,vv,bc[maxn],ans, M;bool g[35][35],can[maxn][23];inline int ADD (int s,int x) {return can[s][x]? ( S|CI[X]): S;} int g[maxn*4+5],jc[233],c[233][233];inline void init () {for (int i=0;i<ci[n];i++) for (int j=0;j<n;j++) if (! (    Ci[j]&i)) {can[i][j]=1;    for (int o=0;o<n;o++) if ((Ci[o]&i) &&g[o][j]) {can[i][j]=0; Break;}}} inline void Calc () {ans=ans* (LL) KSM (jc[n],ha-2)%ha;}        inline void Solve () {f[0][0]=1; int all=ci[n]-1;for (int i=0;i<all;i++) for (It=f[i].begin (); It!=f[i].end (); ++it) for (int j=0,s,to;j<n;j++) if (! (    Ci[j]&i)) {S=i|ci[j],to=add (it->first,j), M=max (M,bc[to]);    Add (F[s][to],it->second);} For (It=f[all].begin (); It!=f[all].end (); ++it) if (bc[it->first]==m) Add (Ans,it->second);} inline int get_line (int N) {memset (g,0,sizeof (g)); g[0]=1; int all=ci[n]-1;for (int i=0;i<all;i++) if (G[i]) for (int j=0 ; j<n;j++) if (! ( Ci[j]&i)) {if ((j&1) &&! ( (I&ci[j-1]) | | (I&ci[j+1])))                Continue    Add (G[i|ci[j]],g[i]); }return G[all];} inline void Qwqwq () {int o[23];for (int i=2;i<=n;i+=2) o[i]=get_line (i); add (Ans,o[n]), add (Ans,o[n]); for (int i=2;i <n;i+=2) Add (ans,o[i]* (ll) o[n-i]%ha*c[n][i]%ha);} int main () {ci[0]=1;for (int i=1;i<=20;i++) ci[i]=ci[i-1]<<1;jc[0]=1;for (int i=1;i<=20;i++) jc[i]=jc[i-1] * (LL) I%ha; c[0][0]=1;for (int i=1;i<=75;i++) {c[i][0]=1;for (int j=1;j<=i;j++) Add (C[i][j],c[i-1][j-1]), add (C[i][j],C[i-1 ][J]);}    scanf ("%d%d", &n,&m); for (int. i=1;i<=m;i++) scanf ("%d%d", &AMP;UU,&AMP;VV), G[uu-1][vv-1]=g[vv-1][uu-1]=1;if (n<=17) {for (int i=1;i <ci[n];i++) bc[i]=bc[i^ (i&-i)]+1;    Init (), solve ();    } else if (n&1) ans=get_line (n);    else Qwqwq ();    Calc (); printf ("%d\n", ans); return 0;}

  

"PKUWC 2018" Stochastic algorithm (60-part-divided approach)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.