Bzoj 2560: Beads/__-Like pressure DP

Source: Internet
Author: User
Tags ming
The following:

Ming Ming has n a very beautiful beads and a number of different colors of the rope. Now Ming Ming wants to use a rope to connect all the beads into a whole.
All beads are now known to be different and numbered with integers 1 through n. For the first and J beads, you can choose to connect them without a rope, or by selecting one of the ci,j in a different color string. If the bead is viewed as a point, the rope is treated as an edge, and all the beads are connected together to form a connecting graph for all points. In particular, beads cannot be connected with themselves.
Ming-Ming wants to know how many different schemes are in place to connect all the beads into one whole. Because the answer can be very large, just output the answer to 1000000007 modulo results. The puzzle :

See count to consider to be dismissed. And in the case of how small n is.
If you do not need to connect then it is to SB question.
Preprocessing G[s] G[s] represents the number of scenarios at the selected state S.
Then let it be divided into two parts which are connected to a certain point.
Enumeration subset, so F[s]=g[s]−∑g[j]∗f[sxorj] F[s]=g[s]-\sum G[j]*f[s XOR J]
Code

 #include <cstdio> #include <cstdlib> #include <cstring> #include <
Iostream> #define LL-long long using namespace std;
Const LL mod=1000000007;
LL n,g[66000],f[66000];
LL C[20][20];
    void Pre (LL S) {g[s]=1; for (ll i=1;i<=n;i++) if ((1<< (i-1)), &s) for (ll j=i+1;j<=n;j++) if ((1<
< (j-1)) &s) (g[s]*= (c[i][j]+1))%=mod;
    int main () {scanf ("%lld", &n);
    for (ll i=1;i<=n;i++) for (ll j=1;j<=n;j++) scanf ("%lld", &c[i][j));
    For (LL i=0;i< (1<<n); i++) pre (i); for (LL s=0; s< (1<<n); s++) {F[s]=g[s];
        LL i=s^ (s&-s);
    For (LL j=i;j;j= (j-1) &i) f[s]= (f[s]-g[j]*f[s^j]%mod+mod)%mod;
printf ("%lld", (f[(1<<n)-1])%mod); }

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.