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