主题:[讨论]关于NOIP2006第2题~~~
请问我用递归做此题,但结果总少一点,为什么???
//PS:我的程序//
program happyjinming;
var cost,zy:array [1..30000] of longint;(cost代表钱数,zy代表重要度)
m,n,ii,big,s:longint;
procedure digit(x,y:longint);
var i:longint;
begin
for i:=y to n do
if (x-cost[i]>=0) then
begin
s:=s+cost[i]*zy[i];
digit(x-cost[i],i+1);
s:=s-cost[i]*zy[i];
end
else if big<s then big:=s;
end;
begin
s:=0;
readln(m,n);
big:=0;
for ii:=1 to n do
readln(cost[ii],zy[ii]);
digit(m,1);
writeln(big);
end.
//PS:我的程序//
program happyjinming;
var cost,zy:array [1..30000] of longint;(cost代表钱数,zy代表重要度)
m,n,ii,big,s:longint;
procedure digit(x,y:longint);
var i:longint;
begin
for i:=y to n do
if (x-cost[i]>=0) then
begin
s:=s+cost[i]*zy[i];
digit(x-cost[i],i+1);
s:=s-cost[i]*zy[i];
end
else if big<s then big:=s;
end;
begin
s:=0;
readln(m,n);
big:=0;
for ii:=1 to n do
readln(cost[ii],zy[ii]);
digit(m,1);
writeln(big);
end.