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

pascal一维数组DP AC的code

Posted by the_magic_five2 at 2015-08-29 21:05:06 on Problem 3624
const maxn=12885;
var
  w,v:array [0..3410] of longint;
  f:array [0..maxn] of longint;
  i,maxw,j,n,x,y:longint;

begin
 while not eof() do
   begin
     readln(n,maxw);
     if eof() then break;
     for i:=1 to n do readln(w[i],v[i]);
     for i:=1 to n do
       begin
          for j:=maxw downto w[i] do
           if f[j]<f[j-w[i]]+v[i] then f[j]:=f[j-w[i]]+v[i];//the DP equation
       end;
     writeln(f[maxw]);
   end;
end.
                                           //by Uchiha Itachi

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