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 |
水题一道。不过题目确实有问题,请大家注意。题目说牛一开始站在tree1下面,是错的。 其实牛是一开始站在哪里都可以。 在代码里加了一句就AC了。 var t,w,i,j,k,ans:longint; f:array[1..1005,0..31,1..2]of longint; ap:array[1..1005,1..2]of integer; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; procedure init; begin readln(t,w); for i:=1 to t do begin readln(k); inc(ap[i,k]); end; fillchar(f,sizeof(f),255); end; function min(a,b:longint):longint; begin if a<b then exit(a) else exit(b); end; procedure dawn; begin f[1,0,1]:=ap[1,1]; f[1,0,2]:=ap[1,2]; //就是这句话,必须给一开始站在tree2也赋初值 for i:=1 to t do for j:=0 to min(i-1,w) do for k:=1 to 2 do begin f[i+1,j+1,3-k]:=max(f[i+1,j+1,3-k],f[i,j,k]+ap[i+1,3-k]); f[i+1,j,k]:=max(f[i+1,j,k],f[i,j,k]+ap[i+1,k]); end; end; procedure pink; begin for i:=0 to w do for j:=1 to 2 do ans:=max(ans,f[t,i,j]); writeln(ans); end; begin init; dawn; pink; end. Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator