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 |
这题是动归,枚举算你做对,也会超时,自己可以算一下复杂度In Reply To:我没辙了 Posted by:ben32 at 2005-05-11 18:38:29 > 不可能有错了呀!大虾们看一下!我是每个房间枚举双向路径的,用迭代做的,这是代码: > type arr1=array[1..100,1..2]of longint; > arr=array[1..500]of record > w:longint; > st:arr1; > end; > var a,b:arr; > c:array[1..500]of longint; > g,m,n,i,j,l,t,s:longint; > begin > readln(n,m); > for i:=1 to m do > begin > read(a[i].w); > a[i].st[1,1]:=i; > end; > readln; > for i:=2 to n do > begin > for j:=1 to m do > read(c[j]); > readln; > for j:=1 to m do > begin > s:=maxlongint; > t:=0; > g:=j; > for l:=j downto 1 do > begin > t:=t+c[l]; > if t+a[l].w<s > then begin > s:=t+a[l].w; > g:=l; > end; > end; > t:=0; > for l:=j to m do > begin > t:=t+c[l]; > if t+a[l].w<s > then begin > s:=t+a[l].w; > g:=l; > end; > end; > b[j].w:=s; > b[j].st:=a[j].st; > b[j].st[i,1]:=g; > b[j].st[i,2]:=j; > b[j].st[1,1]:=a[g].st[1,1]; > end; > a:=b; > end; > g:=1; > for i:=2 to m do > if a[i].w<a[g].w > then g:=i; > writeln(a[g].st[1,1]); > for i:=2 to n do > if a[g].st[i,1]<a[g].st[i,2] > then for j:=a[g].st[i,1] to a[g].st[i,2] do > writeln(j) > else for j:=a[g].st[i,1] downto a[g].st[i,2] do > writeln(j); > end. > 帮我找找错吧!我测了一些特殊数据,都没问题的。也可以给点数据看看!谢谢谢谢! Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator