Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Dp水题~~

Posted by This_poet at 2011-10-14 16:21:13 on Problem 2063
program poj2063;//By_Thispoet
Const
  maxn=100000;
Var
  i,j,k,m,n,p,t                 :Longint;
  f                             :Array[0..maxn]of Longint;
  a,b                           :Array[1..10]of Longint;

Function Max(i,j:Longint):Longint;
begin
  if i>j then exit(i);exit(j);
end;


begin

  readln(t);
  while t>0 do
    begin
      readln(m,k);
      readln(n);
      for i:=1 to n do
        begin
          readln(a[i],b[i]);
          a[i]:=a[i] div 1000;
        end;
      repeat
        p:=m div  1000;
        fillchar(f,sizeof(f),0);
        for i:=1 to n do
          for j:=0 to p-a[i] do
            f[j+a[i]]:=Max(f[j]+b[i],f[j+a[i]]);
        dec(k);
        inc(m,f[p]);
      until k<=0;
      writeln(m);
      dec(t);
    end;

end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator