APIO07-zoo

典型的状压DP,第一次我写的太丑了。。。,更坚定的我的信念,一定要把问题分析透彻再code!
代码:

const maxn=10000;
var w,f:array[1..maxn,0..31] of longint;
    n,ans:longint;
procedure init;
var c,p,k1,k2,hate,happy,j,d:longint;
begin
     fillchar(w,sizeof(w),0);
     readln(n,c);
     while c>0 do begin dec(c);
           read(p,k1,k2);
           hate:=0; while k1>0 do begin dec(k1);
                    read(d); hate:=hate or (1 shl (4-(d+n-p)mod n));
           end;
           happy:=0; while k2>0 do begin dec(k2);
                     read(d); happy:=happy or (1 shl (4-(d+n-p)mod n));
           end;
           for j:=0 to 31 do
           if (j and hate<>0)or((not j)and happy<>0) then inc(w[p,j]);
           readln;
     end;
end;
function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b) end;
procedure work;
var p,j,i:longint;
begin
     for j:=0 to 31 do f[1,j]:=-maxlongint;
     ans:=-1;
     for p:=0 to 31 do begin
         f[1,p]:=w[1,p];
         for i:=2 to n do
         for j:=0 to 31 do
         f[i,j]:=w[i,j]+max(f[i-1,j shr 1],f[i-1,(j shr 1)or 16]);
         ans:=max(ans,max(f[n,p shr 1],f[n,(p shr 1)or 16]));
         f[1,p]:=-maxlongint;
     end;
     write(ans);
end;
begin
     assign(input,'zoo.in'); reset(input);
     assign(output,'zoo.out'); rewrite(output);
     init;
     work;
     close(input);
     close(output);
end.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值