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 |
做了将近1HOUR,幸好是1A,细节还是挺多的。(附PASCAL代码)var a:array[1..1000] of integer; f:array[1..2,0..1000,0..30] of integer; t,w,i,j,ans:integer; function max(a,b:longint):longint; begin if a>b then exit(a) else exit(b); end; begin readln(t,w); for i:=1 to t do readln(a[i]); fillchar(f,sizeof(f),0); for i:=0 to w do f[2,0,i]:=-30000; ans:=0; for i:=1 to t do for j:=0 to w do begin if j>0 then f[a[i],i,j]:=max(f[a[i],i-1,j],f[3-a[i],i-1,j-1])+1 else f[a[i],i,j]:=f[a[i],i-1,j]+1; f[3-a[i],i,j]:=f[3-a[i],i-1,j]; ans:=max(ans,f[a[i],i,j]); end; writeln(ans); end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator