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 |
我觉得这题的正解应该是topsort+dp,绝对的O(mn)...数据再大也不怕...只要能读入。附code...不好意思...只会pascal const px:array [1..4] of longint=(1,-1,0,0); py:array [1..4] of longint=(0,0,1,-1); var m,n:longint; h:array [1..100,1..100] of longint; list,d,tl,f:array [1..10000] of longint; a:array [1..10000,0..4] of longint; function flag(x,y:longint):boolean; begin if (x<1) or (x>m) or (y<1) or (y>n) then flag:=false else flag:=true; end; procedure init; var i,j,k,temp:longint; begin readln(m,n); for i:=1 to m do for j:=1 to n do read(h[i,j]); for i:=1 to m do for j:=1 to n do for k:=1 to 4 do if flag(i+px[k],j+py[k]) and (h[i+px[k],j+py[k]]<h[i,j]) then begin temp:=(i-1)*n+j; inc(a[temp,0]); a[temp,a[temp,0]]:=(i+px[k]-1)*n+j+py[k]; inc(d[(i+px[k]-1)*n+j+py[k]]); end; n:=m*n; end; procedure topsort; var i,head,pt,tail:longint; begin pt:=0; tail:=0; head:=0; for i:=1 to n do if d[i]=0 then begin inc(tail); tl[tail]:=i; end; while pt<n do begin inc(head); inc(pt); list[pt]:=tl[head]; for i:=1 to a[tl[head],0] do begin dec(d[a[tl[head],i]]); if d[a[tl[head],i]]=0 then begin inc(tail); tl[tail]:=a[tl[head],i]; end; end; end; end; procedure dp; var i,j,k,ans:longint; begin ans:=0; for i:=1 to n do f[i]:=1; for i:=1 to n do begin for j:=1 to a[list[i],0] do begin k:=a[list[i],j]; if f[k]<f[list[i]]+1 then f[k]:=f[list[i]]+1; end; if f[list[i]]>ans then ans:=f[list[i]]; end; writeln(ans); end; begin init; topsort; dp; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator