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的代码,顺便贴一个~var a,p,s,d,q:array[0..16000]of longint; f:array[0..100,0..16000]of longint; n,m,i,j,k,l,r:longint; procedure qsort(l,r:longint); var i,j,x,y: longint; begin i:=l; j:=r; x:=s[(l+r) div 2]; repeat while s[i]<x do inc(i); while x<s[j] do dec(j); if not(i>j) then begin y:=s[i]; s[i]:=s[j]; s[j]:=y; y:=a[i]; a[i]:=a[j]; a[j]:=y; y:=p[i]; p[i]:=p[j]; p[j]:=y; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; function max(x,y:longint):longint; begin if x>y then exit(x) else exit(y); end; function min(x,y:longint):longint; begin if x<y then exit(x) else exit(y); end; begin read(n,m); for i:=1 to m do read(a[i],p[i],s[i]); qsort(1,m); for i:=1 to m do begin for j:=0 to s[i]-1 do f[i,j]:=f[i-1,j]; l:=1; r:=1; d[1]:=-1; q[1]:=0; for j:=max(0,s[i]-a[i]) to s[i]-1 do begin k:=f[i-1,j]-p[i]*j; while (l<=r)and(k>=d[r]) do dec(r); inc(r); q[r]:=j; d[r]:=k; end; for j:=s[i] to n do begin while (l<=r)and(q[l]<j-a[i]) do inc(l); f[i,j]:=max(f[i-1,j],f[i,j-1]); if l<=r then f[i,j]:=max(f[i,j],d[l]+p[i]*j); end; end; writeln(f[m,n]); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator