"cf908e" New year and Entity enumeration bit arithmetic +DP

Source: Internet
Author: User

"cf908e" New year and Entity enumeration

Test Instructions : Given $m=2^m-1$, we call a set S to be good when and only if it satisfies: 1.$\forall a\in s,a \mathrm{xor} M \in s$,2.$\forall a,b\in s,a \mathrm{and } b \in s$,3.\forall a\in s,a\le M.

Now given the set T, ask how many good sets of s, satisfying t is a subset of S.

m<=1000,| T|<=50.

The puzzle: Obviously with and take reverse after, we can also achieve OR and XOR. What can we do with the number in T after we have given t? It is easy to find that if bits A and bit B are the same in all numbers, then the number created must satisfy bit A and bit B is the same. We can build all the numbers that meet this condition.

In other words, we just need to determine which bits in s are always the same, that is, the number of schemes that divide m items into several sets (the bell number), which is easily calculated with $m^2$ dp.

But since T is a subset of S, it is equivalent to thinking that some items have been put together, and we can maintain one for each location | t| bit binary state, if the state of the two positions is different, the two locations are not always the same, and the corresponding positions in S cannot always be the same. So we can find out the scheme for all the same states, the bell number, and then multiply the number of scenarios of different states together.

#include <cstdio> #include <cstring> #include <iostream>using namespace std;typedef long Long ll;const ll P=1000000007;bool ban[1010][1010];int bel[1010];int n,m;ll ans;ll Tag[1010],f[1010][1010],s[1010];char str[1010]; int main () {scanf ("%d%d", &m,&n), int i,j,siz;for (i=1;i<=n;i++) {scanf ("%s", str+1); for (j=1;j<=m;j++) if (str[j]== ' 1 ') tag[j]|=1ll<< (i-1);} Ans=f[0][0]=1;for (i=1;i<=m;i++) for (j=1;j<=i;j++) f[i][j]= (f[i-1][j]*j+f[i-1][j-1])%P,s[i]= (S[i]+f[i][j])% P;for (i=1;i<=m;i++) if (!bel[i]) {siz=0;for (j=i;j<=m;j++) if (tag[j]==tag[i]) bel[j]=i,siz++;ans=ans*s[siz]%p;} printf ("%lld", ans); return 0;}

"cf908e" New year and Entity enumeration bit arithmetic +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.