I and OI
Past...

题意:现在需要价格总额为cash的钱,有n种面值的钱币,每种钱币的数目为n[i],面值为d[i],
求在小于或等于所需价格总额的情况下所能组成的最大价值.

分析:多重背包,数组标记.

code:

var   f:array[0..120000] of boolean;
      count:array[0..120000] of longint;
      v,t:array[0..120] of longint;
      n,m,i,j,ans:longint;

begin
      while not eof do
      begin
            read(m,n);
            if (n=0)and(m=0) then halt;
            fillchar(f,sizeof(f),0);
            f[0]:=true;
            ans:=0;
            for i:=1 to n do
            read(t[i],v[i]);
            for i:=1 to n do
            begin
                  fillchar(count,sizeof(count),0);
                  for j:=v[i] to m do
                  if (not f[j])and(f[j-v[i]])and(count[j-v[i]]<t[i])then
                  begin
                        f[j]:=true;
                        count[j]:=count[j-v[i]]+1;
                        if j>ans then ans:=j;
                  end;
            end;
            writeln(ans);
      end;
end.

posted on 2011-08-10 15:05  exponent  阅读(279)  评论(0编辑  收藏  举报