思路:

简单dp。

实现:

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int t,w,x[];
int dp[][][];
int dfs(int now,int cur,int rem)
{
if(dp[now][cur][rem] != -)
return dp[now][cur][rem];
if(now == t)
return ;
int p = dfs(now + ,cur,rem) + (cur == x[now] - );
if(rem >= )
p = max(p, dfs(now, - cur,rem - ) + (cur == x[now] - ));
return dp[now][cur][rem] = p;
}
int main()
{
memset(dp,-,sizeof(dp));
cin >> t >> w;
for(int i = ;i < t;i ++)
{
scanf("%d",&x[i]);
}
cout << dfs(,,w) << endl;
return ;
}

poj2385 Apple Catching的更多相关文章

  1. POJ2385——Apple Catching

                                                $Apple~Catching$ Time Limit: 1000MS   Memory Limit: 6553 ...

  2. poj2385 Apple Catching (线性dp)

    题目传送门 Apple Catching Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 154 ...

  3. poj2385 Apple Catching(dp状态转移方程推导)

    https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人 ...

  4. poj2385 - Apple Catching【动态规划】

    Description It is a little known fact that cows love apples. Farmer John has two apple trees (which ...

  5. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  6. Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 De ...

  7. Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 De ...

  8. 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 1 ...

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

    3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18  Solv ...

随机推荐

  1. POJ3680 Intervals —— 区间k覆盖问题(最小费用流)

    题目链接:https://vjudge.net/problem/POJ-3680 Intervals Time Limit: 5000MS   Memory Limit: 65536K Total S ...

  2. java在某个日期上添加n天的方法实现

    //得到添加n天后的时间字符串 public String getAddDate(Date date,int n){ //格式转换 SimpleDateFormat sdf = new SimpleD ...

  3. easyui 日期范围前后台的设置以及实现

    1.页面部分(引入相应的js) <td class="w40 tl pl10">从日期:</td> <td> <input class=& ...

  4. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...

  5. (转)Linux下 SVN客户端安装

    原地址:http://rtxbc.iteye.com/blog/860092 今天有现场程序连svn服务器一直有异常,于是在现场linux下安装svn client来直接测试,看问题原因: 一:安装s ...

  6. BZOJ_3063_[Usaco2013]Route Designing_DP

    BZOJ_3063_[Usaco2013]Route Designing_DP Description After escaping from the farm, Bessie has decided ...

  7. 线程间操作无效: 从不是创建控件“xxxxxxxx”的线程访问它。

    方法一: Control.CheckForIllegalCrossThreadCalls = false; 方法二:(推荐) this.Invoke(new MethodInvoker(() => ...

  8. 洛谷 - P1012 - 拼数 - 排序

    https://www.luogu.org/problemnew/show/P1012 这道水题居然翻车了,还发现不了bug,服气了.并不是空字符一定比不空要好,要取决于替代它的字符的大小.所以还是直 ...

  9. HDU1016【简单递归.DFS】

    题意:一个环,相邻相加是素数. 思路: 直接深搜就好了.. output limit exceed 了好几发... 因为那个while里面的scanf前面的"~" 后来搜了outp ...

  10. springboot(十二) SpringBoot 性能优化

    代码地址:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo springboot优化主要有三类优化:1.包扫描优化 2. ...