Principle of Bzoj 3812 melody-like pressure dp+ tolerance

Source: Internet
Author: User

Topic: Given an undirected graph, find out how many strong connected graphs are in the generated sub-graph of this undirected graph

We think about the principle of repulsion.

If a graph is not connected, then this image will be indented to form a dag with a >=2 point.

There must be some 0 points in a DAG, and we enumerate the point sets of these points for the repulsion

Specific DP equations and details see code comments written or more detailed I won't say more = =

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 16# Define MOD 1000000007using namespace Std;int n,m,digit[1<<8];int Into[1<<15],out_of[1<<15];long Long F[1<<15],g[1<<15],h[1<<15];long long Power_2[m*m];/*f[s] indicates that the generation of the point set S is strongly connected to the scheme number G[s] represents the generation of the point set S in the sub-figure g, If all the connecting blocks of G are strong, then G has a contribution to g[s] If G has an odd number of connected blocks, then the contribution to G[s] is +1, otherwise -1h[s] indicates how many edges in the induction sub-map of the point set S f[s]=2^h[s]-σ[t is the non-empty set of S]2^ (h[s]-h[t ]) *g[t] (note that at this time G[s] does not include the entire S-strong unicom case) */int Count (int x) {return digit[x>>8] + digit[x&255];} int main () {int i,j,x,y;cin>>n>>m;for (i=1;i<1<<8;i++) digit[i]=digit[i>>1]+ (i&1); for (power_2[0]=1,i=1;i<=m;i++) power_2[i]= (power_2[i-1]<<1)%mod;for (i=1;i<=m;i++) {scanf ("%d%d", &x,&y); out_of[1<<x-1]|=1<<y-1;into[1<<y-1]|=1<<x-1;} for (i=1;i<1<<n;i++) {int One=i&-i,sta=i^one;//one is any point in the S collection//sta for the S collection to remove the remaining points set outside one h[i]=h[sta]+count ( Into[one]&sta) +count (Out_of[one]&sta);(J=sta;j; (--j) &=sta)//Enumerate point sets that are not connected to one (g[i]+=mod-f[i^j]*g[j]%mod)%=mod;static int w[1<<15];//w[t] The number of edges that represent points in the collection T to the point in the collection s-t f[i]=power_2[h[i]];for (j=i;j; (--j) &=i)//enumeration T set {if (j==i) W[j]=0;else{int temp= (i^j) & -(I^J);//Select a point in the S-t collection W[j]=w[j^temp]-count ((I^J) &out_of[temp]) +count (J&into[temp]);} (F[i]+=mod-power_2[h[i^j]+w[j]]*g[j]%mod)%=mod;} (G[i]+=f[i])%=mod;} cout<<f[(1<<n) -1]<<endl;return 0;}


Principle of Bzoj 3812 melody-like pressure dp+ tolerance

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.