比赛 暑假培训一 评测结果 AWWWW
题目名称 选数 最终得分 10
用户昵称 zhai 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-17 14:52:36
显示代码纯文本
program choose(f1,f2);
  type
    sy=array[1..20]of longint;
    sx=array[0..10000]of integer;
  var
    f1,f2:text;
    a:sy;
    b,c:sx;
    n,k,ans,j:integer;
    e:longint;
    procedure init;
      var
        s,s1:string;
        l,i,x,c:integer;
      begin
        assign(f1,'choose.in');reset(f1);
        assign(f2,'choose.out');rewrite(f2);
        readln(f1,n,k);
        readln(f1,s);
        close(f1);
        s:=s+' ';
        s1:='';
        for i:=1 to n do begin
          l:=pos(' ',s);
          s1:=copy(s,1,l-1);
          delete(s,1,l);
          val(s1,x,c);
          a[i]:=x;
        end;
      end;
    procedure jian;
      var
        i,x,c:integer;
        f:boolean;
      begin
        c:=2;
        b[1]:=2;
        for x:=2 to 9997 do begin
          f:=true;
          i:=2;
          while f and(i<=trunc(sqrt(x))+1)do begin
            if x mod i=0 then f:=false;
            i:=i+1;
          end;
          if f then begin b[c]:=x;inc(c);end;
        end;
        b[0]:=c;
      end;
    function pan(e:longint):boolean;
      var
        i,j,c:integer;
        f:boolean;
      begin
        c:=b[0];
        i:=1;
        f:=true;
        while f and(b[i]<=trunc(sqrt(e))+1)do begin
          if e mod b[i]=0 then f:=false;
          i:=i+1;
        end;
        pan:=f;
      end;
    procedure make(m:integer);
      var
        l1,l,i:integer;
      begin
        if m=k+1 then begin if pan(e) then inc(ans);exit;end;
        for i:=c[m-1]+1 to n do
          begin
            e:=e+a[i];
            c[m]:=i;
            make(m+1);
            e:=e-a[i];
          end;
      end;
  begin
    init;
    jian;
    make(1);
    write(f2,ans);
    close(f2);
  end.