bzoj2560 Bead Sub (subset DP)

Source: Internet
Author: User

Ming Ming has n very beautiful beads and a number of different root colors of the rope. Now Ming Ming want to use a rope to connect all the beads into a whole.
All beads are now known to be different, numbered in integers 1 through n. For the I beads and the J beads, you can choose to connect them without a rope, or choose one of the different color cords in the ci,j root to connect them. If you think of a bead as a point, think of the rope as an edge, and connect all the beads as a whole to make a connected graph of all the points. In particular, beads cannot connect with themselves.
Ming Ming wants to know how many different schemes are in total to connect all the beads into a single whole. Because the answer can be large, you only need to output the result of the answer to 1000000007 modulo.

Solution

Immortal DP.

We shilling G[i] indicates that in this state of I, the number of options for a random edge, this can be easily made out.

Then we consider subtracting the illegal from the state, we can consider enumerating subsets, forcing the current set into two disconnected sets, so the number of scenarios is f[s]*g[s^i].

To avoid duplication, we need to find a fixed point from the set, forcing the point to be in the S collection so that it does not appear in the g[s^i] and then again in G[s].

Code

#include <iostream>#include<cstdio>#defineN 22using namespacestd;Const intMod=1000000007;Long Longa[n][n],f[1<< -],g[1<< -];intN;intMain () {scanf ("%d",&N);  for(intI=1; i<=n;++i) for(intj=1; j<=n;++j) scanf ("%lld",&A[i][j]); intMa= (1<<n)-1;  for(intI=1; i<=ma;++i) {G[i]=1;  for(intj=1; j<=n;++j)if(i& (1<<j-1))           for(intk=j+1; k<=n;++k)if(i& (1<<k-1)) (G[i]*= (a[j][k]+1))%=MoD; }     for(intI=1; i<=ma;++i) {       for(ints=i& (I-1); S s=i& (S-1))        if(! ((s^i) & (I&-i))) (f[i]+= (F[s]*g[s^i])%mod)%=MoD; F[i]= ((G[i]-f[i])%mod+mod)%MoD; } printf ("%lld", F[ma]); return 0;}

 

bzoj2560 Bead Sub (subset DP)

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.