比赛 暑假培训五 评测结果 AAAAWWWWWA
题目名称 开心的金明 最终得分 50
用户昵称 rottenwood 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-22 09:36:35
显示代码纯文本
program happy;
type
shuzu=array[0..10000] of integer;
shuzu1=array[0..10000,0..10000]of longint;
var
v,w:shuzu;
b:shuzu1;
a,c,i,j,k,m,n:longint;
f1,f2:text;
function max(x,y:longint):longint;
begin
if x>y then max:=x
else max:=y;
end;
begin
assign(f1,'happy.in');reset(f1);
assign(f2,'happy.out');rewrite(f2);
readln(f1,n,m);
for i:=1 to m do
begin
 readln(f1,v[i],w[i]);
 w[i]:=v[i]*w[i];
 end;
   for i:=1 to m do
     for j:=1 to n do
     if j-v[i]<0 then
     b[i,j]:=b[i-1,j]
     else
     begin
     b[i,j]:=max(b[i-1,j],b[i-1,j-v[i]]+w[i]);
       end;
       writeln(f2,b[m,n]);
       close(f2);
       end.