[APIO2007] Zoo----like pressure dp

Source: Internet
Author: User

[APIO2007] Zoo

Title Description

The new round Zoo is the pride of the Asia-Pacific region. Located on an island in the Pacific Ocean, the circular Zoo contains a large circle of fences with an animal in each fence.

As shown in the following:

You are the public director of the zoo. All you have to do is make everyone who comes to the zoo as happy as possible.

There are a group of children visiting the zoo today, and you want them to have a good time at the zoo.

But this is not an easy thing-some animals some children like, some animals some children afraid.

For example, Alex likes cute monkeys and koalas and is afraid of a lion with sharp teeth.

And Polly will like it because the lion has a beautiful mane, but is afraid of the smelly koala.

You can choose to remove some animals from the fence so that children are not afraid.

But you can't remove all the animals, otherwise the children will have no animals to watch.

Each child stands outside the large fence and can see 5 consecutive fences.

You get information about all the animals that children like and are afraid of. When one of the following two situations occurs, the child will be pleased:

    • At least one of the animals he was afraid of was removed.

    • At least one of his favorite animals has not been removed.

For example, consider the children and animals:

If you remove the animals with fences 4 and 12. Alex and Ka-shu will be happy because at least one of the animals they fear has been removed.

This will also make Chaitanya happy, because he likes the fences 6 and 8 in which the animals are preserved.

But Polly and Hwan will be unhappy because they don't see any animals they like, and the animals they fear are still there.

This arrangement makes three children happy.

Now, in another way, if you remove the animals in fences 4 and 6, Alex and Polly will be happy because the animals they fear are removed.

Chaitanya will also be happy, although his favorite animal 6 is removed, he can still see the fence 8 inside his favorite animals.

The same hwan will be happy to see 12 of the animals they like. The only thing unhappy is Ka-shu.

If you only remove the animals in fence 13, Ka-shu will be happy because there is an animal he is afraid of being removed, and Alex, Polly, Chaitanya and Hwan will also be happy because they can see at least one of their favorite animals.

So there are 5 children who will be happy.

This method makes the most of the children happy.

Input format:

The first line of input contains two integer n,c, separated by a space. N is the number of fences (1≤n≤10), C is the number of children (1≤c≤50 000).

The fence is numbered in a clockwise direction,..., N.

The next line of C, each line describing a child, describes the following form given:

E F L X1 X2 ... XF Y1 Y2 ... Yl

which

E represents the number of the first fence the child can see (1≤e≤n), which means that the child can see the fence as e,e+1,e+2,e+3,e+4.

Note that if the number exceeds N will continue to count from 1 onwards.

For example: When n=14,e=13, children can see the fence for 13,14,1,2 and 3.

F indicates the number of animals that children are afraid of.

L indicates the number of animals a child likes.

Fence X1, X2, ..., the XF contains animals that children are afraid of.

Fence Y1, Y2, ..., YL contains animals that children like.

X1, X2, ..., XF, Y1, Y2, ..., YL is 22 different numbers, and the fences are all visible to children.

The children have been lined up in the order of the first fence they can see (so that the smallest e corresponds to the children in the first, the largest e corresponds to the children in the last one).

Note that there may be more than one child corresponding to the E is the same.

output Format:

Only one number is output, which means that the maximum number of children can be delighted.

The surface is very long, but the problem itself is not difficult.

Note that children can see a limited number of points, decisive pressure.

\ (DP (i,s) \) indicates the number of children happy at the current enumeration to \ (I\) with a status of \ (s\)

Well, there are

\ (DP (I,S) =max (DP (i-1, (s\;and\;15) <<1), DP (I-1, (s\;and\;15) <<1\;or\;1)) +...\)

(corresponds to the current selection or not selected)

\ (... \) How to ask?

\ (... \) represents the number of children happy in the \ (s\) state for the I\ column, which can be preprocessed.

Time complexity: \ (O (2^{5}*n) \)

Have you finished???

No, the final state and the beginning cannot conflict.

The method of determination is not difficult to think of, external enumeration at the beginning of the state.

Time complexity: \ (O (2^{10}*n) \)

code here

[APIO2007] Zoo----like pressure dp

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.