比赛 20101117 评测结果 WWTTTTTTWW
题目名称 拯救 最终得分 0
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2010-11-17 09:55:01
显示代码纯文本
program savey;
var
  data:array [1..1000] of boolean;
  s:char;
  n,i:integer;
  step:longint;
function get(num:integer):longint;
var i,tmp:longint;
begin
  if num=1 then begin
    data[1]:=not(data[1]);
    exit(1);
  end
  else if num=2 then begin
    data[2]:=not(data[2]);
    if data[1]=false then exit(get(1)+1) else exit(1);
  end
  else begin
    tmp:=0;
    if data[num-1]=false then tmp:=get(num-1);
	for i:=num-2 downto 1 do if data[i]=true then tmp:=tmp+get(i);
	data[num]:=not(data[num]);
        exit (tmp+1);
  end;
end;
begin
  assign (input,'savey.in');
  reset (input);
  assign (output,'savey.out');
  rewrite (output);
  readln (n);
  fillchar (data,sizeof(data),0);
  for i:=1 to n do begin
    read (s);
	if s='1' then data[i]:=true;
  end;
  close (input);
  step:=0;
  for i:=n downto 1 do
    if data[i] then
	  step:=step+get(i);
  writeln (step);
  close (output);
end.