Train of Thought: binary, bitwise operation |, to mark the status. For example, if 2, 4, and 6 appear in a set, use the binary number 101010 = (decimal) 2 + 8 + 32 = 42 to record this set !!, Because the m value is <= 14, a maximum of 1 <14 States are available. Use these binary | operations to generate a new set. Then the statistics are used to obtain the answer .. After reading the question solution, it seems very simple, but it is too difficult to think about it .. I really admire the children I think ..
AC code:
[Cpp]
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <cstring>
# Include <queue>
# Include <map>
# Include <algorithm>
Using namespace std;
Int a [1 <15];
Int main ()
{
Int I, j, n, m;
While (~ Scanf ("% d", & n, & m ))
{
Memset (a, 0, sizeof ());
Int k, x, y;
Int ans = 0;
While (n --)
{
Scanf ("% d", & k );
Y = 0;
While (k --)
{
Scanf ("% d", & x );
Y = y | (1 <x-1 );
}
A [y] = 1;
For (I = 0; I <= 1 <14; I ++)
{
If (a [I])
A [I | y] = 1;
}
}
For (I = 1; I <= 1 <14; I ++)
If (a [I]) ans ++;
Printf ("% d \ n", ans );
}
}
# Include <stdio. h>
# Include <stdlib. h>
# Include <iostream>
# Include <cstring>
# Include <queue>
# Include <map>
# Include <algorithm>
Using namespace std;
Int a [1 <15];
Int main ()
{
Int I, j, n, m;
While (~ Scanf ("% d", & n, & m ))
{
Memset (a, 0, sizeof ());
Int k, x, y;
Int ans = 0;
While (n --)
{
Scanf ("% d", & k );
Y = 0;
While (k --)
{
Scanf ("% d", & x );
Y = y | (1 <x-1 );
}
A [y] = 1;
For (I = 0; I <= 1 <14; I ++)
{
If (a [I])
A [I | y] = 1;
}
}
For (I = 1; I <= 1 <14; I ++)
If (a [I]) ans ++;
Printf ("% d \ n", ans );
}
}