比赛 |
NOIP2008集训模拟2 |
评测结果 |
WWWEEETTEE |
题目名称 |
阿鲁高的远航 |
最终得分 |
0 |
用户昵称 |
E.M.B.E.R |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-11 11:22:21 |
显示代码纯文本
program EmberAsh;
var
i,j,k,t,v,a,w,max,t1,t2,head:longint;
n,b:array[0..1000]of longint;
f:array[0..1000,0..100]of longint;
step:array[1..1000]of longint;
fin,fout:text;
procedure try(now,have,cost:longint);
var
i,j,k,n1,h1,c1:longint;
begin
if now=t+1 then
begin
if cost<max then max:=cost;
f[now,have]:=cost;
end
else
begin
for i:=0 to a do
begin
n1:=now;h1:=have;c1:=cost;
h1:=h1+i-n[now];
c1:=c1+b[now]*i+h1*w;
if h1>=0 then
if (c1<f[n1,h1])or(f[n1,h1]=0) then
begin
f[n1,h1]:=c1;
try(n1+1,h1,c1);
end;
end;
end;
end;
BEGIN
assign(fin,'sail.in');reset(fin);
assign(fout,'sail.out');rewrite(fout);
readln(fin,t,v,a,w);
for i:=1 to t do
readln(fin,n[i],b[i]);
try(1,0,0);
max:=maxlongint;
for i:=0 to v do
if f[t,i]<max then
begin
max:=f[t,i];
head:=1;
step[head]:=i;
end;
for i:=t-1 downto 1 do
for j:=1 to v do
if f[i,j]=max then
begin
inc(head);
step[head]:=j+n[i];
max:=f[i,j];
end;
writeln(fout,max);
for i:=head downto 1 do
writeln(fout,step[i]);
close(fin);close(fout);
END.