Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 3006
The cherry keyboard I just bought feels really good. Unfortunately, I am not used to coding errors. I wrote all kinds of wrong keys for a single question all morning. debug .....
At first, I thought DFS would not work.
Then, we can enumerate the Union sets of all the two sets in a two-repeating loop. The three-repeating loop can enumerate the Union sets of all three sets. Then, N subsets seem to require n re-loops, NP problems ,,,,,
The practice is to simulate a small number, because there are only 14, so the pressure storage
Example 1
Four subsets: 1, 2, 4
Binary 0001 0010 0011 0100
The first and other three operations get 0001 0010 0011 0100 0011 0101 ....
Then the second number and the new number are different or
In the code, the second round starts with I + 1 and repeats. In fact, it does not save much time (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;}
All Union sets that can be generated by the HDU 3006 enumeration set