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 |
我的DP 好像有错,谁帮我看看[Pascal]program p2353; var n,m:integer; num:array[0..101,0..501]of longint; f:array[0..101,0..501,1..2]of longint; out:array[1..600]of integer; procedure init; var i,j:integer; begin readln(m,n); for i:=1 to m do begin for j:=1 to n do read(num[i,j]); readln; end; end; procedure main; var i,j:integer; begin for i:=2 to m do begin f[i,0,1]:=maxint; f[i,n+1,1]:=maxint; end; for i:=1 to n do f[1,i,1]:=num[1,i]; for i:=2 to m do begin for j:=1 to n do if f[i-1,j,1]<f[i,j-1,1] then begin f[i,j,1]:=f[i-1,j,1]+num[i,j]; f[i,j,2]:=j; end else begin f[i,j,1]:=f[i,j-1,1]+num[i,j]; f[i,j,2]:=j-1; end; for j:=n downto 1 do if f[i,j+1,1]+num[i,j]<f[i,j,1] then begin f[i,j,1]:=f[i,j+1,1]+num[i,j]; f[i,j,2]:=j+1; end; end; end; procedure outit; var i,j,min,sum,c,l:integer; begin min:=maxint; sum:=0; c:=m; for i:=1 to n do if f[m,i,1]<min then begin min:=f[m,i,1]; sum:=i; end; l:=0; repeat if sum=0 then break; inc(l); out[l]:=sum; if f[c,sum,2]=sum then c:=c-1 else sum:=f[c,sum,2]; until false; for i:=l downto 1 do writeln(out[i]); end; begin init; main; outit; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator