Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
pascal一维数组DP AC的codeconst 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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator