dp 动态规划 之C - Apple Catching 简单基础
终于开始写dp了,还很不熟练
Each minute, one of the two apple trees drops an apple. Bessie, having much practice, can catch an apple if she is standing under a tree from which one falls. While Bessie can walk between the two trees quickly (in much less than a minute), she can stand under only one tree at any time. Moreover, cows do not get a lot of exercise, so she is not willing to walk back and forth between the trees endlessly (and thus misses some apples).
Apples fall (one each minute) for T (1 <= T <= 1,000) minutes. Bessie is willing to walk back and forth at most W (1 <= W <= 30) times. Given which tree will drop an apple each minute, determine the maximum number of apples which Bessie can catch. Bessie starts at tree 1.
Input
* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.
Output
Sample Input
7 2
2
1
1
2
2
1
1
Sample Output
6
Hint
Seven apples fall - one from tree 2, then two in a row from tree 1, then two in a row from tree 2, then two in a row from tree 1. Bessie is willing to walk from one tree to the other twice.
OUTPUT DETAILS:
Bessie can catch six apples by staying under tree 1 until the first two have dropped, then moving to tree 2 for the next two, then returning back to tree 1 for the final two.
状态转移方程:dp[i][j] = max(dp[i-1][j], dp[i-1][j-1]),然后判断当前是否在第i分钟掉苹果的那颗树下,是的话,dp[i][j]++。
对状态转移方程的解释如下:第i分钟能得到的苹果数量,等于在第i-1分钟时,在树1和树2下得到苹果的最大值。j为偶数则在树1下面,奇数则在树2下面。
!
dp 动态规划 之C - Apple Catching 简单基础的更多相关文章
- poj 2385 Apple Catching 基础dp
Apple Catching Description It is a little known fact that cows love apples. Farmer John has two ap ...
- poj2385 Apple Catching (线性dp)
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 154 ...
- Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9831 Accepted: 4779 De ...
- 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 ...
- 【POJ】2385 Apple Catching(dp)
Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13447 Accepted: 6549 D ...
- 【POJ - 2385】Apple Catching(动态规划)
Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...
- POJ 2385 Apple Catching【DP】
题意:2棵苹果树在T分钟内每分钟随机由某一棵苹果树掉下一个苹果,奶牛站在树#1下等着吃苹果,它最多愿意移动W次,问它最多能吃到几个苹果.思路:不妨按时间来思考,一给定时刻i,转移次数已知为j, 则它只 ...
- Day 5 笔记 dp动态规划
Day 5 笔记 dp动态规划 一.动态规划的基本思路 就是用一些子状态来算出全局状态. 特点: 无后效性--狗熊掰棒子,所以滚动什么的最好了 可以分解性--每个大的状态可以分解成较小的步骤完成 dp ...
- (转)dp动态规划分类详解
dp动态规划分类详解 转自:http://blog.csdn.NET/cc_again/article/details/25866971 动态规划一直是ACM竞赛中的重点,同时又是难点,因为该算法时间 ...
随机推荐
- Python和Java编程题(一)
今天偶尔看到一个博客有贴了五十个编程题,决定以后两天左右做一道题 题目来源:http://blog.sina.com.cn/s/blog_60fafdda0100wb21.html 1.题目 一个数如 ...
- XtraBackup的备份原理与应用示例
一.XtraBackup简介与安装 XtraBackup是一款免费的在线开源数据库备份解决方案,适用于所有版本的MySQL和MariaDB.XtraBackup支持对InnoDB热备,是一款物理备份工 ...
- RowVersion 用法
在数据表更新时,如何表征每个数据行更新时间的先后顺序?最简单的做法是使用RowVersion(行版本)字段,它和时间戳(TimeStamp)类型的功能相似,只不过TimeStamp 已过时,应避免用于 ...
- STM32F4 MDK5软件仿真 error : no 'read' permission
问题描述 CPU:STM32F407 MDK5软件模拟提示没有读写权限,只能一步一步运行.提示代码如下: *** error 65: access violation at 0x40023800 : ...
- inheritPrototypal.js
// 原型式继承 // 其基本思路是借助原型可以基于已有的对象创建新的对象 function object(o){ function F(){} F.prototype = o; return new ...
- Python 操作文件
open() 函数 模式 说明 r 只读模式 w 只写模式,文件不存在自动创建:存在则清空再写 a 只追加写,在文件最后追加写 r+ 打开一个文件用于读写.文件指针将会放在文件的开头. w+ 打开一个 ...
- canvas实现验证码
在通常的登录界面我们都可以看到验证码,验证码的作用是检测是不是人在操作,防止机器等非人操作,防止数据库被轻而易举的攻破. 验证码一般用PHP和java等后端语言编写. 但是在前端,用canva或者SV ...
- 交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别
交叉编译器 arm-linux-gnueabi 和 arm-linux-gnueabihf 的区别 自己之前一直没搞清楚这两个交叉编译器到底有什么问题,特意google一番,总结如下,希望能帮到道上和 ...
- loadrunner 脚本优化-关联函数web_reg_save_param()函数详解
脚本优化-关联函数web_reg_save_param()函数详解 by:授客 QQ:1033553122 Insert->New Step,打开Add Step对话框 选择函数web_re ...
- long数值 转换为时间
项目中,服务器端经常给客户端开发人员传一个长整形的时间数据, 对于一个 长整形 1446801883000,可以明显的看出 是以毫秒为单位的,因为最后有三个零,如果没有连续3个零的话就要判断单位了 那 ...