poj 2385【动态规划】
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 14007 | Accepted: 6838 |
Description
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; int dp[][];
int app[]; int main()
{
int T,W;
scanf("%d%d",&T,&W);
memset(dp,,sizeof(dp));
for(int i=;i<=T;i++){
scanf("%d",&app[i]);
}
if(app[]==) dp[][]=;
else dp[][]=;
for(int i=;i<=T;i++){
dp[i][]=dp[i-][]+app[i]%;
for(int j=;j<=W;j++){
dp[i][j]=max(dp[i-][j],dp[i-][j-]);
if(j%+==app[i]) dp[i][j]++;
}
}
int ans=;
for(int i=;i<=W;i++)
ans=max(ans,dp[T][i]);
printf("%d\n",ans);
return ;
}
poj 2385【动态规划】的更多相关文章
- poj 2385 Apple Catching(记录结果再利用的动态规划)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 有两颗苹果树,在每一时刻只有其中一棵苹果树会掉苹果,而Bessie可以在很短的时 ...
- 【POJ - 2385】Apple Catching(动态规划)
Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...
- nyoj 17-单调递增最长子序列 && poj 2533(动态规划,演算法)
17-单调递增最长子序列 内存限制:64MB 时间限制:3000ms Special Judge: No accepted:21 submit:49 题目描述: 求一个字符串的最长递增子序列的长度 如 ...
- 【DP】POJ 2385
题意:又是Bessie 这头牛在折腾,这回他喜欢吃苹果,于是在两棵苹果树下等着接苹果,但苹果不能落地后再接,吃的时间不算,假设他能拿得下所有苹果,但是这头牛太懒了[POJ另一道题目说它是头勤奋的奶牛, ...
- poj 3034 动态规划
思路:这是一道坑爹的动态规划,思路很容易想到,就是细节. 用dp[t][i][j],表示在第t时间,锤子停在(i,j)位置能获得的最大数量.那么只要找到一个点转移到(i,j)收益最大即可. #incl ...
- poj 2498 动态规划
思路:简单动态规划 #include<map> #include<set> #include<cmath> #include<queue> #inclu ...
- poj 2287 动态规划
用贪心简单证明之后就是一个从两头取的动态规划 #include <iostream> #include <cstring> #include <cstdio> #i ...
- POJ 2533 动态规划入门 (LIS)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 42914 Accepte ...
- DP:Apple Catching(POJ 2385)
牛如何吃苹果 问题大意:一个叫Bessie的牛,可以吃苹果,然后有两棵树,树上苹果每分钟会掉一个,这只牛一分钟可以在两棵树中往返吃苹果(且不吃地上的),然后折返只能是有限次W,问你这只叫Bessie的 ...
随机推荐
- Spring Cloud Eureka集群配置及注意事项(Greenwich版本)
Spring Cloud Eureka集群配置及注意事项(Greenwich版本) 一·概述 Spring Cloud Netflix Eureka 是一个提供服务注册与发现的套件.服务提供者只需要将 ...
- tortoisegit如何删除远程分支
图片来自:https://zhidao.baidu.com/question/134542616148384045.html
- eclipse设置提示信息
1.设置 java 文件的代码提示功能 .abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ () 2.设置 xml 文件的代码提示功能 打 开 ...
- (2)卷积 & 卷积和
参考资料:<信号与系统(第二版)> 杨晓非 何丰 连续信号的是卷积积分,离散信号的是卷积和. 脉冲分量 任意非周期信号,将横坐标分为若干个微小等分,得到Δτ为宽,f(kΔτ)为高的一系列微 ...
- windows 和 mac 文件夹共享问题汇总
目标:windows上的文件夹,共享给MAC,mac可以将文件复制到windows上来 windows设置共享文件夹,然后在mac上访问 假设win的ip地址是10.10.27.11,则mac上远程方 ...
- 利用HttpWebRequest通过POST Json数据在.net后台实现不同平台间的数据传输
/// <summary> /// 返回JSon数据 /// </summary> /// <param name="JSONData">要处理 ...
- H5C3--拖拽接口的使用和实例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- loadrunner录制脚本时登录密码转md5
在录制用户注册登录脚本时,常常会遇到web程序对用户密码进行加密处理.在很多时候采用的加密方式为MD5. 这时有两种处理方式: 一.所有用户采用同一密码 例如:每个用户名的密码都为e10adc3949 ...
- Yann LeCun清华演讲:深度学习与人工智能的未来
2017年3月22日下午,Facebook人工智能研究院院长.纽约大学终身教授Yann LeCun在清华大学大礼堂为校内师生以及慕名而来的业内人士呈现了一场主题为<深度学习与人工智能的未来(De ...
- JS---案例:开机动画
案例:开机动画 由上下两部分组成,先下面的高变为0 ,再最大的div宽为0,形成一个缩小到没有的动画效果 点击的X是在背景图上的,在上面设置了一个空的span用于注册点击事件 <!DOCTYPE ...