[Dynamic Planning] Hacker's CrackDown ultraviolet A 11825, crackdown11825
The abstract mathematical model is to take as many subsets as possible, so that each subset can cover the complete set.
# Include <algorithm> # include <cstring> # include <cstdio> using namespace std; int n; int P [1000], cover [1000], f [1000]; int main () {scanf ("% d", & n); for (int I = 0; I <n; I ++) {int m, x; scanf ("% d", & m); P [I] = 1 <I; while (m --) {scanf ("% d", & x ); P [I] | = (1 <x) ;}} for (int S = 1; S <n; S ++) {cover [S] = 0; for (int I = 0; I <n; I ++) {if (S & (1 <I) cover [S] | = P [I];} f [0] = 0; int ALL = (1 <n)-1; for (int S = 1; S <n; S ++) {f [S] = 0; for (int S0 = S; S0; S0 = (S0-1) & S) // This is the most important part, subset operation {if (cover [S0] = ALL) {f [S] = max (f [S], f [S ^ S0] + 1 ); // compare the complement set + 1 with the maximum value} printf ("% d", f [ALL]); return 0 ;}