HDU 3006 Enumeration Collection of all the set of aggregates that can be produced

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php?

pid=3006

Just bought Cherry keyboard feel good but not accustomed to write code always wrong. One inscribed all morning, are all kinds of press the wrong key debug .....

I started thinking about DFS discovery.

And then I think that the two loops are able to enumerate the set of all 2 sets. A 3-cycle can enumerate the set of all 3 sets, so N-subsets seem to require N-cycles. NP problem Ah,, ...

The practice is still a small number to simulate, because there are only 14. So the pressure storage

As the first example

Four subsets of 1,2,3,4

Binary 0001 0010 0011 0100

The first one with the other three or operation gets 0001 0010 0011 0100 0011 0101 ....

Then the second number and the new number are different or

The second cycle of the code i+1 start, put back and forth, in fact, not much time to save O (╯-╰) o

#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #include < Cmath> #include <queue>using namespace std; #define IN (s) freopen (S, "R", stdin) #define CL (A, B) memset (A, B,    sizeof (a)) const int MAXN = 1<<15;int Vis[maxn],ans[maxn];int main () {//in ("hdu3006.txt");    int n,m;    int k;        while (~SCANF ("%d%d", &n,&m)) {CL (vis,0);        int cnt=0;            for (int j=0;j<n;j++) {scanf ("%d", &k);            int t=0,a=0;                for (int i=0;i<k;i++) {scanf ("%d", &t);            a|=1<< (t-1);                } if (!vis[a]) {vis[a]=1;            Ans[cnt++]=a;        }} int ct=cnt;            for (int i=0;i<ct;i++) {int s=ans[i];                    for (int j=i+1;j<cnt;j++) {if (!vis[(S|ans[j])] && i!=j) { vis[s|ans[j]]=1;                ANS[CNT++]=S|ANS[J];    }}} printf ("%d\n", CNT); } return 0;}



HDU 3006 Enumeration Collection of all the set of aggregates that can be produced

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.