bzoj1151: [CTSC2007] Zoo-like pressure DP

Source: Internet
Author: User

Description

The new round Zoo is the pride of the Asia-Pacific region. Located on a small island in the Pacific Ocean, the circular Zoo consists of a large circle of fences, each with a
Species of animals. 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. A group of children come to visit the zoo today, you hope
Hope that they can have a good time in the zoo. But this is not an easy thing-some animals have some children like, some animals have
Some children are afraid. For example, Alex likes cute monkeys and koalas and is afraid of a lion with sharp teeth. And Polly will have a beautiful mane for the lion.
And like it, but afraid of a smelly koala. You can choose to remove some animals from the fence so that children are not afraid. But you can't remove all
Animals, otherwise children will have no animals to see. 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 also
Would make Chaitanya happy because he liked the fences 6 and 8 in which the animals were preserved. But Polly and Hwan would be unhappy, for they
They don't see any animals they like, and the animals they're afraid of are still there. This arrangement makes three children happy. Now, in a different way,
If you remove the animals from fences 4 and 6, Alex and Polly will be happy because the animals they fear are removed. Chaitanya will Also
Pleased, though his favorite animal 6 was removed, he could still see the fence 8 inside his favorite animal. The same hwan can also be seen from
The animals that you like 12 and happy. The only thing unhappy is Ka-shu. If you only remove the animals in fence 13, Ka-shu will be happy because there are
A creature he feared had been removed, and Alex, Polly, Chaitanya and Hwan would be delighted, as they could all see at least one of their favorite
The animal of joy. So there are 5 children who will be happy. This method makes the most of the children happy.

Input

The first line of input contains two integers n, C, separated by a space.
N is the number of fences (10≤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 describes a child's information,
Given in the following form: E F L X1 X2 ... XF Y1 Y2 ... Yl
Where: E represents the number of the first fence that the child can see (1≤e≤n),
In other words, the child can see the fence for E, e+1, e+2, E+3, e+4.
Note that if the number exceeds n will continue to count from 1 onwards.
such as: When N=14, e=13, the child can see the fence for 13,14,1, 2 and 3.
F indicates the number of animals that the child is afraid of.
L indicates the number of animals the child likes.
Fence X1, X2, ..., the XF contains animals that the child is afraid of.
Fence Y1, Y2, ..., YL contains the children's favorite animals.
X1, X2, ..., XF, Y1, Y2, ..., yl is 22 different integers,
And the fence is what the children can see.
The children have been lined up in the order they can see the first fence number from small to large.
(So the smallest e corresponds to the children ranked 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

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

Exercises

Look at the data range, only the children can see the railing range of pressure.
Then we use \ (num[i]][j]\) to indicate the number of happy people who have observed the range of \ (i- (i+4) \) in the case of a state of \ (j\) .
Then use \ (f[i][j]\) to indicate the observed range of \ (i- (i+4) \), the state is \ (j\) the largest number of children happy, and then by the first \ (i-1\) fence to go without removing the transfer
\[f[i][j]=max (f[i-1][(j\&15) <<1],f[i-1][(j\&15) <<1|1]) +num[i][j]\]
And because it is a ring, we enumerate the initial state, only the state at the end is the same as the original state, to update the answer.
Then remember to give the other State a negative value each time the answer is enumerated, preventing the answer from being affected.

Code
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std;const int Maxn=1e4+10;const int maxm= (1<<5) +10;const int inf=0x3f3f3f3f;int n,c,ans;int num[maxn][maxm];int F [MAXN]    [Maxm];int Id[maxn];int Main () {Ios::sync_with_stdio (false);    cin>>n>>c;        for (int i=1;i<=c;i++) {int e,a,f,l,x=0,y=0,ht,lv;        cin>>e>>f>>l;a=e;            for (int i=1;i<=5;i++) {if (e>n) e=1;        Id[e++]=i;            } for (int i=1;i<=f;i++) {cin>>ht;ht=id[ht];        x|=1<< (ht-1);            } for (int i=1;i<=l;i++) {cin>>lv;lv=id[lv];        y|=1<< (Lv-1); } for (int i=0;i< (1<<5); i++) if ((i&y) | |                ((i^ ((1<<5)-1)) &x))    num[a][i]++;        } for (int i=0;i< (1<<5); i++) {memset (f[0],-inf,sizeof (f[0)));        f[0][i]=0; for (int j=1;j<=n;j++) For (int k=0;k< (1<<5); k++) F[j][k]=max (f[j-1][(k&15) <<1],f[j-1][(k&15) <<1|1]) +num[j]        [K];    Ans=max (F[n][i],ans); } printf ("%d\n", ans);}

bzoj1151: [CTSC2007] 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.