jzoj4314 老司机

Description

这里写图片描述

Input

这里写图片描述

Output

这里写图片描述

Sample Input

4
1 3 6 6

Sample Output

3
1 2 3
这里写图片描述

Data Constraint

这里写图片描述

算法讨论

因为cost<=50,所以k不会超过6,暴力即可。
var
  a,q:array[0..100] of longint;
  c:array[0..100] of boolean;
  n,i,j,e,r,k,t,p,aa,bb,cc,min:longint;
procedure xh(o:longint);
var
  w:longint;
begin
  for w:=50-o downto 0 do
    if c[w] then c[w+o]:=true;
end;
function check:boolean;
var
  w:longint;
begin
  fillchar(c,sizeof(c),false);
  c[0]:=true;
  xh(i);xh(e);xh(k);
  xh(j);xh(r);xh(t);
  for w:=1 to n do
    if not c[a[w]] then exit(false);
  exit(true);
end;
begin
  assign(input,'driver.in');reset(input);
  assign(output,'driver.out');rewrite(output);
  readln(n);
  min:=maxlongint;
  for i:=1 to n do
    read(a[i]);
  for i:=0 to 1 do
    for j:=0 to 2 do
      for k:=0 to 4 do
        for e:=0 to 10 do
          for r:=0 to 16 do
            for t:=00 to 32 do
              if check then
                begin
                  p:=0;
                  if i<>0 then inc(p);
                  if j<>0 then inc(p);
                  if k<>0 then inc(p);
                  if e<>0 then inc(p);
                  if r<>0 then inc(p);
                  if t<>0 then inc(p);
                  if p>=min then continue;
                  min:=p;
                  q[1]:=i;q[2]:=j;q[3]:=k;
                  q[4]:=e;q[5]:=r;q[6]:=t;
                  for aa:=1 to 5 do
                    for bb:=aa+1 to 6 do
                      if q[aa]>q[bb] then
                        begin cc:=q[aa];q[aa]:=q[bb];q[bb]:=cc;end;
                end;
  writeln(min);
  for aa:=1 to 6 do
    if q[aa]<>0 then write(q[aa],' ');
  close(input);close(output);
end.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值