1 条题解

  • 0
    @ 2025-2-14 21:04:21

    Pascal :

    var
    n:array[1..2,0..10000] of longint;
    s,x,j,m:longint;
    
    procedure f(s,i:longint);
    begin
      if s-n[1,i]=0 then
      begin n[2,i]:=1;
      for j:=1 to x do
        if n[2,j]=1 then writeln('number:',j,' ','weight:',n[1,j]);
      halt; end;
      if(s<0) or (i<=0) or ((s>0) and (i=0)) then exit;
      n[2,i]:=1;
      f(s-n[1,i],i-1);
      n[2,i]:=0;
      f(s,i-1);
    
    
    end;
    begin
      readln(x,s);
      for j:=1 to x do
      begin
       read(m);
       n[1,j]:=m;
       end;
       f(s,x);
       write('not found');
    end.
    
    
    • 1

    信息

    ID
    635
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者