P3384: [Usaco2004 Nov]Apple Catching 接苹果

一道DP题, f[i,j,k] 表示 第 k 时刻 由 1 位置 变换 j 次 到达 当前 i 棵树 注意也要维护 变换 0 次的情况。

 1 var i,j,k,t,w,now:longint;
 2 tree:array[1..2,0..1001] of longint;
 3 f:array[1..2,0..50,0..1001] of longint;
 4 function max(a,b:longint):longint;
 5 begin
 6   if a>b then exit(a)
 7     else exit(b);
 8 end;
 9 begin
10   readln(t,w);
11   for i:=1 to t do
12     begin
13       readln(now);
14       tree[now,i]:=1;
15     end;
16     for i:=1 to t do
17     for j:=0 to w+i-max(i,w) do
18       for k:=1 to 2 do
19         begin
20           if (j=0) and (k<>2) then begin
21             f[k,j,i]:=f[k,j,i-1]+tree[k,i];
22             continue;
23           end
24           else if j=0 then continue;
25           f[k,j,i]:=max(f[k,j,i],tree[k,i]+max(f[3-k,j-1,i-1],f[k,j,i-1]));
26           //writeln(i,‘ ‘,j,‘ ‘,f[k,j,i]);
27         end;
28   writeln(max(f[1,w,t],f[2,w,t]));
29 end.

   (转载请注明出处:http://www.cnblogs.com/Kalenda/)
时间: 2024-08-06 22:57:56

P3384: [Usaco2004 Nov]Apple Catching 接苹果的相关文章

BZOJ 3384: [Usaco2004 Nov]Apple Catching 接苹果( dp )

dp dp( x , k ) = max( dp( x - 1 , k - 1 ) + *** , dp( x - 1 , k ) + *** ) *** = 0 or 1 ,根据情况 (BZOJ 1750双倍经验) ------------------------------------------------------------------------ #include<cstdio> #include<cstring> #include<algorithm>

3384/1750: [Usaco2004 Nov]Apple Catching 接苹果

3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18  Solved: 16[Submit][Status][Discuss] Description 很少有人知道奶牛爱吃苹果.农夫约翰的农场上有两棵苹果树(编号为1和2),每一棵树上都长满了苹果.奶牛贝茜无法摘下树上的苹果,所以她只能等待苹果从树上落下.但是,由于苹果掉到地上会摔烂,贝茜必须在半空中接住苹果(没

POJ 2385 Apple Catching 接苹果 DP

题目链接:POJ 2385 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7858   Accepted: 3846 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently number

Apple Catching(POJ 2385)

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac

POJ2385 Apple Catching 【DP】

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8018   Accepted: 3922 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac

Apple Catching(dp)

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac

POJ2385——Apple Catching

Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8062   Accepted: 3951 Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, eac

3385: [Usaco2004 Nov]Lake Counting 数池塘

3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 22  Solved: 21[Submit][Status][Discuss] Description 农夫约翰的农场可以表示成N×M(1≤N,M≤100)个方格组成的矩形.由于近日的降雨, 在约翰农场上的不同地方形成了池塘.每一个方格或者有积水(’W’)或者没有积水(’.’).农夫约翰打算数出他的农场上共形成了多少池塘.一个

BZOJ 3385: [Usaco2004 Nov]Lake Counting 数池塘

题目 3385: [Usaco2004 Nov]Lake Counting 数池塘 Time Limit: 1 Sec  Memory Limit: 128 MB Description 农夫约翰的农场可以表示成N×M(1≤N,M≤100)个方格组成的矩形.由于近日的降雨, 在约翰农场上的不同地方形成了池塘.每一个方格或者有积水(’W’)或者没有积水(’.’).农夫约翰打算数出他的农场上共形成了多少池塘.一个池塘是一系列相连的有积水的方格,每一个方格周围的八个方格都被认为是与这个方格相连的. 现