题目:http://www.lydsy.com/JudgeOnline/problem.php?id=1151
状压DP,枚举前面4个,使得环型变线型。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<utility>
#include<set>
#include<bitset>
#include<vector>
#include<functional>
#include<deque>
#include<cctype>
#include<climits>
#include<complex>
//#include<bits/stdc++.h>适用于CF,UOJ,但不适用于poj using namespace std; typedef long long LL;
typedef double DB;
typedef pair<int,int> PII;
typedef complex<DB> CP; #define mmst(a,v) memset(a,v,sizeof(a))
#define mmcy(a,b) memcpy(a,b,sizeof(a))
#define re(i,a,b) for(i=a;i<=b;i++)
#define red(i,a,b) for(i=a;i>=b;i--)
#define fi first
#define se second
#define m_p(a,b) make_pair(a,b)
#define SF scanf
#define PF printf
#define two(k) (1<<(k)) template<class T>inline T sqr(T x){return x*x;}
template<class T>inline void upmin(T &t,T tmp){if(t>tmp)t=tmp;}
template<class T>inline void upmax(T &t,T tmp){if(t<tmp)t=tmp;} const DB EPS=1e-;
inline int sgn(DB x){if(abs(x)<EPS)return ;return(x>)?:-;}
const DB Pi=acos(-1.0); inline int gint()
{
int res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
}
inline LL gll()
{
LL res=;bool neg=;char z;
for(z=getchar();z!=EOF && z!='-' && !isdigit(z);z=getchar());
if(z==EOF)return ;
if(z=='-'){neg=;z=getchar();}
for(;z!=EOF && isdigit(z);res=res*+z-'',z=getchar());
return (neg)?-res:res;
} const int maxN=;
const int maxC=; #define wei(v,k) (((v)>>(k-1))&1) int N,C;
struct Tkid
{
int pos,afraid,love;
inline void input()
{
int i,F,L;
pos=gint()+;F=gint();L=gint();
afraid=;re(i,,F){int t=gint();if(pos>N && t<=)t+=N;afraid|=two(pos-t);}
love=;re(i,,L){int t=gint();if(pos>N && t<=)t+=N;love|=two(pos-t);}
}
inline int happy(int state){return ((~state)&love) || (state & afraid);}
}kid[maxC+]; int F[maxN+][two()+];
int ans; int main()
{
freopen("bzoj1151.in","r",stdin);
freopen("bzoj1151.out","w",stdout);
int i,j,l;
N=gint();C=gint();
re(i,,C)kid[i].input();
int S;
re(S,,two()-)
{
mmst(F,-);
F[][S]=;
int head=,tail;
re(i,,N)re(j,,two()-)re(l,,)
{
while(head<=C && kid[head].pos<i)head++;
if(F[i-][j]==-)continue;
int k,t;
k=(j*+l)%two();
t=F[i-][j];
for(tail=head;tail<=C && kid[tail].pos==i;tail++)if(kid[tail].happy(k))t++;
upmax(F[i][k],t);
}
re(i,N+,N+)re(j,,two()-)
{
while(head<=C && kid[head].pos<i)head++;
if(F[i-][j]==-)continue;
int k,t;
k=(j*+wei(S,+N-i))%two();
t=F[i-][j];
for(tail=head;tail<=C && kid[tail].pos==i;tail++)if(kid[tail].happy(k))t++;
upmax(F[i][k],t);
}
re(j,,two()-)upmax(ans,F[N+][j]);
}
cout<<ans<<endl;
return ;
}