思路:

简单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. SQL JOIN连接分类[转]

    1.内联接(典型的联接运算,使用像 =  或 <> 之类的比较运算符):包括相等联接和自然联接: 内联接使用比较运算符根据每个表共有的列的值匹配两个表中的行:    2.外联接.外联接可以 ...

  2. timestamp 转 date 处理后再转timestamp

    package com.jmu.ccjoin.service.impl; import java.sql.Timestamp;import java.util.Calendar;import java ...

  3. 转:Oracle:删除表空间

    原文:http://space.itpub.net/40239/viewspace-365948 OMF和非OMF管理的数据文件在DROP TABLESPACE时是否会自动删除,做了测试: SQL&g ...

  4. HDU - 1874 畅通工程续(最短路径)

    d.已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离. s.最短路径 c.Dijkstra单源最短路 /* Dijkstra单源最短路 权值必须是非负 单源最短路径,Dijkstra算法 ...

  5. SPOJ:Help BTW(二分)

    BTW wants to buy a gift for her BF and plans to buy an integer array. Generally Integer arrays are c ...

  6. SpringMVC之使用Validator接口进行验证

    对于任何一个应用而言在客户端做的数据有效性验证都不是安全有效的,这时候就要求我们在开发的时候在服务端也对数据的有效性进行验证.SpringMVC自身对数据在服务端的校验有一个比较好的支持,它能将我们提 ...

  7. -webkit-text-size-adjust 处理设置字体<12px

    -webkit-text-size-adjust 1.当样式表里font-size<12px时,中文版chrome浏览器里字体显示仍为12px,这时可以用  html{-webkit-text- ...

  8. VC链接hid.lib出错问题解决方案

    写一个HID的客户端小程序,调用了一些HID API,但是链接时出现了奇怪的现象. 尽管我已经把头文件和lib文件加入到了VC的Include和Lib目录中,但不管我用VC链接,还是在DDK环境下链接 ...

  9. Java递归应用:输出树形菜单

    转自:https://blog.csdn.net/zhangzeyuaaa/article/details/24574769

  10. chromium浏览器开发系列第一篇:如何获取最新chromium源码

    背景:      最近摊上一个事儿,领导非要让写一篇技术文章,思来想去,自己接触chrome浏览器时间也不短了,干脆就总结一下吧.于是乎,本文顺理成章.由于有些细节必需描述清楚,所以这次先讲如何拿到c ...