记录编号 48895 评测结果 AAAAAAAAAA
题目名称 [Vijos 1071] 新年趣事之打牌 最终得分 100
用户昵称 Gravatar天天快乐 是否通过 通过
代码语言 Pascal 运行时间 0.001 s
提交时间 2012-11-06 20:38:37 内存使用 0.18 MiB
显示代码纯文本
var n,totalw,i,t,s:longint;
    w,q,ans:array[0..1000]of longint;

procedure find(x:longint);
var i,j,b:longint;
begin
  if x=0 then
    begin
      inc(s);
      ans:=q;
      for i:=1 to q[0]-1 do
        if (w[q[i]]=w[q[i]+1]) and (q[i+1]<>q[i]+1) then inc(s);
      if (q[q[0]]+1<=n) and (w[q[q[0]]]=w[q[q[0]]+1]) then inc(s);
      if s>1 then begin write(-1);halt;end;
    end
  else begin
    b:=q[q[0]]+1;
    for i:=b to n do
      if ((q[q[0]+1]=-1) or (w[i]<>w[q[q[0]+1]])) and (x-w[i]>=0) then
        begin
          inc(q[0]);q[q[0]]:=i;
          find(x-w[i]);;
          dec(q[0]);
        end;
   end;
end;

begin
  assign(input,'bagb.in');
  assign(output,'bagb.out');
  reset(input);
  rewrite(output);
  read(totalw,n);
  s:=0;
  w[0]:=-1;q[0]:=0;
  for i:=1 to n do begin read(w[i]);s:=s+w[i];q[i]:=-1;end;
  if totalw>=s then begin write(0);halt;end;
  totalw:=s-totalw;
  s:=0;
  find(totalw);
  if s=0 then write(s)
    else begin
      write(ans[1]);
      for i:=2 to ans[0] do write(' ',ans[i]);
    end;
end.