Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

做了将近1HOUR,幸好是1A,细节还是挺多的。(附PASCAL代码)

Posted by noipchampion at 2011-08-16 16:32:40 on Problem 2385
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator