A DP question, F[i,j,k] indicates that the K time is reached by the 1-position Transformation J-time to the current I-tree note also to maintain the situation of the transformation 0 times.
1 varI,j,k,t,w,now:longint;2tree:array[1..2,0..1001] of Longint;3f:array[1..2,0.. -,0..1001] of Longint;4 function Max (a,b:longint): Longint;5 begin6 ifA>B then exit (a)7 Elseexit (b);8 end;9 beginTen readln (t,w); One fori:=1to T Do A begin - Readln (now); -tree[now,i]:=1; the end; - fori:=1to T Do - forj:=0To W+i-max (I,W) Do - fork:=1To2 Do + begin - if(j=0) and (k<>2) THEN BEGIN +f[k,j,i]:=f[k,j,i-1]+Tree[k,i]; A Continue; at End - Else ifj=0ThenContinue; -F[k,j,i]:=max (F[k,j,i],tree[k,i]+max (f[3-k,j-1. io1],f[k,j,i-1])); - //Writeln (I, ", J," ', F[k,j,i]); - end; -Writeln (Max (f[1, w,t],f[2, w,t])); inEnd.
View Code
(Reproduced Please specify Source: http://www.cnblogs.com/Kalenda/)
P3384: [Usaco2004 nov]apple catching pick up apples