微笙无上吧 关注:21贴子:174
  • 2回复贴,共1

【1021】【buy low,buy lower】解题报告

只看楼主收藏回复

program buylow;
var
n:longint;
stock:array[1..5000]of longint;
dp:array[1..5000]of longint;
sum:array[1..5000]of longint;{存放方案数}
flag:array[1..5000] of boolean;{标记重复方案}
maxnum,maxplan:longint;
{最大购买次数、最大购买方案数}
procedure fstart; {输入输出准备}
begin
assign(input,'d:\test\data1.in');
reset(input);
assign(output,'d:\test\data1.out');
rewrite(output);
end;
procedure fend; {结束工作}
begin
close(input);
close(output);
end;
procedure input;
var
i:longint;
begin
readln(n);
for i:=1 to n do
read(stock[i]);
fillchar(flag,sizeof(flag),true);
end;
procedure MaxBuyNum;
var
i,j:longint;
begin
maxnum:=0;
maxplan:=0;{}
{求最长下降序列}
for i:=1 to n do
begin
dp[i]:=1;
sum[i]:=1;
for j:=1 to i-1 do
begin
if stock[i]=stock[j] then flag[j]:=false;
{如果出现相同的数,则选择后面的,前面的数标记不能用}
if (stock[i]<stock[j])and(flag[j]) then
if (dp[i]<dp[j]+1) then
begin
dp[i]:=dp[j]+1 ;
sum[i]:=sum[j];{不是同一次可以购买的}
end
else
if(dp[i]=dp[j]+1)then
inc(sum[i],sum[j]);
{同一次可以购买的则方案数累加}
end;
if dp[i]>maxnum then
maxnum:=dp[i]; {找最大购买次数}
end;
{求最大购买方案数}
for i:=1 to n do
if(maxnum=dp[i])and(flag[i])then
inc(maxplan,sum[i]);{最后一次购买的方案累加}
end;
procedure output;
var
i:longint;
begin
writeln(maxnum,' ',maxplan);
for i:=1 to n do
write(sum[i]:3);
writeln;
readln;readln;
end;
begin
fstart;
input;
MaxBuyNum;
output;
fend;
end.



1楼2012-03-01 15:15回复
    上面这段代码时坑爹的!


    IP属地:北京2楼2012-03-01 17:51
    回复
      2025-05-30 06:01:16
      广告
      大手一挥经验到手


      IP属地:北京3楼2012-03-01 17:52
      回复