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

虽然知道怎么做,但为什么这么写不对呢

Posted by 322000 at 2011-09-23 19:34:23 on Problem 3257
var
   f:array [0..1001,0..1001] of longint;
   l,n,c,i,j:longint;a,b,v,w:array [0..10001] of longint;
function max(a,b:longint):longint;
begin
   if a>=b then exit(a) else exit(b);
end;
procedure qsort(p,r:longint);
var
   i,j,o,n:longint;
begin
   if p<r then
   begin
      o:=b[random(r-p+1)+p];
      i:=p-1;j:=r+1;
      while true do
      begin
         repeat inc(i) until b[i]>=o;
         repeat dec(j) until b[j]<=o;
         if i<j then begin n:=a[i];a[i]:=a[j];a[j]:=n;
                           n:=b[i];b[i]:=b[j];b[j]:=n;
                           n:=w[i];w[i]:=w[j];w[j]:=n;
                           n:=v[i];v[i]:=v[j];v[j]:=n; end else break;
      end;
      qsort(p,j);
      qsort(j+1,r);
   end;
end;
begin
   read(l,n,c);
   for i:=1 to n do
   begin
      read(a[i],b[i],v[i],w[i]);
      b[i]:=b[i]+a[i];
   end;
   qsort(1,n);
   for i:=1 to n do
      for j:=c downto w[i] do
         f[b[i],j]:=max(f[a[i],j-w[i]]+v[i],f[b[i],j]);
   if f[l,c]<>0 then writeln(f[l,c]) else writeln(-1);
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