题目描述
有两个寂寞的程序员J和Y,J说他可以两分钟敲8000字,Y说不信,于是J与Y的4kb/min机器人进行了一场打字比赛。机器人以匀高速敲着乱码,而J找到了帮他超越手速的键:CTRL。J可以花不同的时间进行以下操作:
敲一个字符
按CTRL-A
按CTRL-C
按CTRL-V
(具体效果请在记事本内实验)
你需要制定一个操作顺序,使得J在n毫秒内输入的字符数最多。
【数据范围】
30%的数据保证 n≤10
100%的数据保证 1≤n≤1,000;1≤cost≤n
输入格式
第一行五个整数 n cost_input cost_CtrlA cost_CtrlC cost_CtrlV,四个cost分别对应进行四个操作需要耗费的毫秒数
输出格式
一行一个整数,表示能够输入的最多字符数
样例输入
样例输出
type arr=array[0..1000] of longint;
var n,a,b,c,d:longint;
f:array[0..5000] of arr;
ans:arr;
m,i,j,k,sum:longint;
procedure jia(var now:arr; x:longint);
var i:longint;
begin
{for i:=1 to now[0] do
begin
now[i]:=now[i]+x;
now[i+1]:=now[i+1]+now[i] div 1000000;
now[i]:=now[i] mod 1000000;
end;
if now[now[0]+1]>0 then inc(now[0]);}//fuck
now[1]:=now[1]+x;
for i:=1 to now[0] do
begin
now[i+1]:=now[i+1]+now[i] div 1000000;
now[i]:=now[i] mod 1000000;
end;
if now[now[0]+1]>0 then inc(now[0]);
end;
procedure cheng(var now:arr;x:longint);
var i:longint;
begin
now[1]:=now[1]*x;
for i:=2 to now[0] do
begin
now[i]:=now[i]*x;
now[i]:=now[i]+now[i-1] div 1000000;
now[i-1]:=now[i-1] mod 1000000;
end;
{if now[now[0]+1]>0 then inc(now[0]);}
while now[now[0]]>=1000000 do
begin
inc(now[0]); now[now[0]]:=now[now[0]-1] div 1000000;
now[now[0]-1]:=now[now[0]-1] mod 1000000;
end;
end;
function right(arr1,arr2:arr):boolean;
var i:longint;
begin
if arr1[0]>arr2[0] then exit(true);
if arr1[0]<arr2[0] then exit(false);
for i:=arr1[0] downto 1 do
if arr1[i]>arr2[i] then exit(true)
else if arr1[i]<arr2[i] then exit(false);
exit(false);
end;
begin
assign(input,'p2.in'); assign(output,'p2.out');
reset(input); rewrite(output);
readln(n,a,b,c,d);
b:=b+c;
f[0,0]:=1; f[0,1]:=0;
for i:=1 to n do
begin
if i-a>=0 then
begin
f[i]:=f[i-a]; jia(f[i],1); {if i=377 then writeln(f[i-a,0],'OX');}
end
else begin
f[i,0]:=1; f[i,1]:=0;
end;
{if i=377 then begin end;}
for j:=2 to (i-b) div d do
begin
ans:=f[i-b-d*j]; cheng(ans,j);
if right(ans,f[i]) then begin f[i]:=ans;
{if i=376 then writeln(j,' fuck',i-b-d*j);} end;
end;
end;
write(f[n,f[n,0]]);
for i:=f[n,0]-1 downto 1 do
begin
if f[n,i]<100000 then write(0);
if f[n,i]<10000 then write(0);
if f[n,i]<1000 then write(0);
if f[n,i]<100 then write(0);
if f[n,i]<10 then write(0);
write(f[n,i]);
end;
close(input); close(output);
end.