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 |
求大牛指点~~~!!!!!!!!!!!!!为什么 m downto 就可以ac?~~~ 自己写的自己都不明白~~0.0 program lonely; var p,d,temp,n,m,z,i,j,k,maxv,ans1,ans2:longint; ans3:ansistring; ss:string; g:array[0..30,0..1000] of string; h,f:array[0..30,0..1000] of longint; sub,sum:array[0..3000] of longint; procedure print; var t1,t2:longint; begin t1:=(ans1+ans2) div 2; t2:=(ans2-ans1) div 2; writeln('Best jury has value ',t1,' for prosecution and value ',t2,' for defence:'); writeln(ans3); end; begin while not eof do begin inc(z); read(n,m); if (n=0)and(m=0) then break; writeln('Jury #',z); temp:=20*m; fillchar(f,sizeof(f),255); fillchar(h,sizeof(h),0); for i:=0 to 30 do for j:=0 to 1000 do g[i,j]:=''; maxv:=0; fillchar(sub,sizeof(sub),0); fillchar(sum,sizeof(sum),0); for i:=1 to n do begin read(p,d); sub[i]:=p-d+20; sum[i]:=p+d; inc(maxv,sub[i]); end; f[0,0]:=0; for j:=1 to n do for i:=m downto 1 do // 求解!!!!!! for k:=maxv-sub[j] downto 0 do if (f[i-1,k]<>-1)and(h[i-1,k]<j) then if (f[i-1,k]+sum[j]>f[i,k+sub[j]])and(k+sub[j]<=maxv) then begin f[i,k+sub[j]]:=f[i-1,k]+sum[j]; str(j,ss); g[i,k+sub[j]]:=g[i-1,k]+' '+ss; h[i,k+sub[j]]:=j; end; ans1:=maxlongint shr 1; ans2:=0; for i:=0 to maxv do if (f[m,i]<>-1) then if (abs(i-temp)<abs(ans1))or((abs(ans1)=abs(i-temp))and(f[m,i]>=ans2)) then begin ans1:=i-temp; ans2:=f[m,i]; ans3:=g[m,i]; end; print; writeln; end; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator