记录编号 207971 评测结果 AAAAAAAAAAAAAAAAAAAA
题目名称 [NOIP 2015]斗地主 最终得分 100
用户昵称 Gravatar转瞬の电流 是否通过 通过
代码语言 Pascal 运行时间 0.007 s
提交时间 2015-11-14 20:43:55 内存使用 0.17 MiB
显示代码纯文本
program ddz;
var
a:array[0..15]of byte;
i,j,k,m,n,s,o,p,q,dan,shuang,min:longint;
procedure tui(x,y:longint);
var
u,v,w,dd,ss:shortint;
begin
if a[x-1]=1 then inc(dan);
if a[x-1]=2 then inc(shuang);
if a[x-1]>2 then exit;
if x>14 then begin
dd:=dan;
ss:=shuang;
while (ss>0)and(dd<=-2) do begin dd:=dd+2; dec(ss); end;
if (dd<0) then dd:=dd+a[0] else if a[0]<>0 then dd:=dd+1;{then dd:=dd+2 else if a[0]=2 then
                begin if dd>=0 then dd:=dd+1 else dd:=1 end
else dd:=dd+a[0];}
if dd<0 then dd:=0;
if ss<0 then ss:=0;
if y+dd+ss<=min then min:=y+dd+ss;
if a[x-1]=1 then dec(dan);
if a[x-1]=2 then dec(shuang);
exit;
end;
if a[x]= 4 then
 begin
 a[x]:=0;
 dan:=dan-2;
 tui(x+1,y+1);
 dan:=dan+2;
 shuang:=shuang-2;
 tui(x+1,y+1);
 shuang:=shuang+2;
 a[x]:=4;
 end;
if a[x]>=3 then
 begin
 a[x]:=a[x]-3;
 dan:=dan-1;
 tui(x+1,y+1);
 dan:=dan+1;
 shuang:=shuang-1;
 tui(x+1,y+1);
 shuang:=shuang+1;
 a[x]:=a[x]+3;
 end;
if (x<=10)and(x>=3) then
 begin
 w:=0;
 v:=x;
 while (a[v]>0)and(v<=14) do
  begin
  inc(v);
  inc(w);
  end;
 if w>=5 then
 for u:=5 to w do
 begin
 for v:=x to x+u-1 do
 dec(a[v]);
 tui(x+1,y+1);
 tui(x,y+1);
 for v:=x to x+u-1 do
 inc(a[v]);
 end;
 end;
if (x<=12)and(x>=3) then
begin
w:=0;
v:=x;
 while (a[v]>=2)and(v<=14) do
 begin
 inc(v);
 inc(w);
 end;
if w>=3 then
 for u:=3 to w do
 begin
 for v:=x to x+u-1 do
 a[v]:=a[v]-2;
 tui(x+1,y+1);
 tui(x,y+1);
 for v:=x to x+u -1 do
 a[v]:=a[v]+2;
 end;
end;
if (x<=12)and(x>=3) then
begin
w:=0;
v:=x;
 while (a[v]>=3)and(v<=14) do
 begin
 inc(v);
 inc(w);
 end;
if w>=3 then
for u:=3 to w do
begin
 for v:=x to x+u-1 do
 a[v]:=a[v]-3;
 tui(x+1,y+1);
 for v:=x to x+u -1 do
 a[v]:=a[v]+3;
 end;
end;
tui(x+1,y);
if a[x-1]=1 then dec(dan);
if a[x-1]=2 then dec(shuang);

end;
begin
assign(input,'landlords.in');
reset(input);
assign(output,'landlords.out');
rewrite(output);
readln(m,n);
for i:=1 to m do
 begin
 fillchar(a,sizeof(a),0);
 for j:=1 to n do
  begin
  readln(o,p);
  if o=1 then inc(a[14]) else
  inc(a[o]);
  end;
  min:=100;
  dan:=0;
  shuang:=0;
  tui(2,0);
  writeln(min);
  end;
  {close(input);}
  close(output);
end.