"Codeforces" E. New Year and Entity enumeration

Source: Internet
Author: User

"topic" E. New Year and Entity enumeration

"Test Instructions" the given set T contains N m long binary numbers, which require a set of S number that contains the set T and satisfies the following conditions: The length <=m, the non-and the result are all in the collection. (Details of the original question)

"Algorithm" Mathematics (Bell number)

The problem of "solution" really does not understand this practice, so it is simple to write.

First, do not consider that s must contain set T.

For a scenario, the bitwise consideration, all digits with the bit I and up to get the smallest number containing that bit, recorded as F[i].

For F[x]≠f[y], there are f[x]&f[y]=0, proof:! (F[x]&f[y]) &f[x] This number contains X-bits and <f[x].

Then the f[x of different bits], either equal or unequal and no overlap, then the number of schemes corresponds to the number of sets divided by 1~m (Bell number).

Bell number: B (n) =σc (n-1,k) *b (k), k=0~n-1. Solve the Complexity O (m^2).

Finally consider t, different bits if the binary number of vertical view is different then its F value must not be the same, so divided into a number of parts of the respective solution and then multiply is the answer.

#include <cstdio>#include<map>#definell Long Longusing namespacestd;Const intmaxn=1010, mod=1e9+7;intc[maxn][maxn],f[maxn],n,m;ll B[maxn];map<ll,int>MP;intMain () {scanf ("%d%d",&m,&N);  for(intI=0; i<n;i++){         for(intj=1; j<=m;j++){            intx; scanf ("%1d",&x); B[J]+ = (1ll*x) <<i; }    }     for(intI=1; i<=m;i++) mp[b[i]]++;  for(intI=0; i<=m;i++) {c[i][0]=1;  for(intj=1; j<=i;j++) c[i][j]= (c[i-1][j-1]+c[i-1][J])%MOD; } f[0]=1;  for(intI=1; i<=m;i++){         for(intj=0; j<i;j++) f[i]= (f[i]+1ll*c[i-1][J]*F[J]%MOD)%MOD; }    intans=1;  for(Map<ll,int>::iterator It=mp.begin (); It!=mp.end (); it++) ans=1ll*ans*f[it->second]%MOD; printf ("%d", ans); return 0;}
View Code

"Codeforces" E. New Year and Entity enumeration

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.