【POJ】2385 Apple Catching(dp)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13447 | Accepted: 6549 |
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.
Source

还要预处理一下。
#include <cstdio>
#include <algorithm>
using namespace std;
int dp[][],a[];//dp[i][j]:在i时来回j次
int inv(int m)
{
if(m==) return ;
else return ;
}
int main()
{
int t,w,a[],maxnum=-;
scanf("%d%d",&t,&w);
for(int i=;i<=t;i++) scanf("%d",&a[i]);
for(int i=;i<=t;i++)
dp[i][]=dp[i-][]+a[i]%;
for(int i=;i<=t;i++)
for(int j=;j<=w;j++)
{
dp[i][j]=max(dp[i-][j-],dp[i-][j]);
if(a[i]==j%+)
dp[i][j]++;//拿住苹果
}
printf("%d",dp[t][w]);
return ;
}
【POJ】2385 Apple Catching(dp)的更多相关文章
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- 【POJ】3616 Milking Time(dp)
Milking Time Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10898 Accepted: 4591 Des ...
- 【BZOJ】1068: [SCOI2007]压缩(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1068 发现如果只设一维的话无法转移 那么我们开第二维,发现对于前i个来说,如果确定了M在哪里,第i个 ...
- 【POJ】2234 Matches Game(博弈论)
http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论 ...
- 【51nod1519】拆方块[Codeforces](dp)
题目传送门:1519 拆方块 首先,我们可以发现,如果第i堆方块被消除,只有三种情况: 1.第i-1堆方块全部被消除: 2.第i+1堆方块全部被消除:(因为两侧的方块能够保护这一堆方块在两侧不暴露) ...
- 【bzoj1925】地精部落[SDOI2010](dp)
题目传送门:1925: [Sdoi2010]地精部落 这道题,,,首先可以一眼看出他是要我们求由1~n的排列组成,并且抖来抖去的序列的方案数.然后再看一眼数据范围,,,似乎是O(n^2)的dp?然后各 ...
- 【ZOJ2278】Fight for Food(dp)
BUPT2017 wintertraining(16) #4 F ZOJ - 2278 题意 给定一个10*10以内的地图,和p(P<=30000)只老鼠,给定其出现位置和时间T(T<=1 ...
- 【vijos】1764 Dual Matrices(dp)
https://vijos.org/p/1764 自从心态好了很多后,做题的确很轻松. 这种题直接考虑我当前拿了一个,剩余空间最大能拿多少即可. 显然我们枚举每一个点拿出一个矩形(这个点作为右下角), ...
- 【Luogu】P3856公共子串(DP)
题目链接 DP.设last[i][j]是第i个串字符'j'所在的最后的位置,f[i][j][k]是第一个串匹配到i,第二个串匹配到j,第三个串匹配到k,最多的公共子串数. 那么我们三重循环i.j.k, ...
随机推荐
- 在线机器学习FTRL(Follow-the-regularized-Leader)算法介绍
看到好文章,坚决转载!哈哈,学术目的~~ 最近几个同事在做推荐平台的项目,都问到怎么实现FTRL算法,要求协助帮忙实现FTRL的算法模块.今天也是有空,赶紧来做个整理.明天还要去上海参加天善智能组织的 ...
- ng-if 判断条件中不能 使用变量名字拼接,switch可以
- mysql在innodb索引下b+树的高度问题。
B+树索引介绍 B+树索引的本质是B+树在数据库中的实现.但是B+树索引有一个特点是高扇出性,因此在数据库中,B+树的高度一般在2到3层.也就是说查找某一键值的记录,最多只需要2到3次IO开销.按磁盘 ...
- js之隔行换色
HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <ti ...
- 博通BCM53101M以太网交换芯片原理解析
Quality of Service 服务质量 BCM53101M的QoS为每个端口提供6个内部队列以支持6种不同的流量类别(traffic class, TC).在流量拥塞的情况下,可通过拥塞管理, ...
- Android学习笔记之Activity详解
1 理解Activity Activity就是一个包含应用程序界面的窗口,是Android四大组件之一.一个应用程序可以包含零个或多个Activity.一个Activity的生命周期是指从屏幕上显示那 ...
- HDU2896 病毒侵袭 【AC自动机】
HDU2896 病毒侵袭 Problem Description 当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻....在这样的时刻,人们却异常兴奋--我们能在有生之年看到500年一 ...
- 《DSP using MATLAB》示例Example 8.20
%% ------------------------------------------------------------------------ %% Output Info about thi ...
- 关于git的基本使用
参考:http://www.cnblogs.com/mengdd/p/3585038.html
- 自定义DelegatingHandler为ASP.NET Web Api添加压缩与解压的功能
HTTP协议中的压缩 Http协议中使用Accept-Encoding和Content-Encoding头来表示期望Response内容的编码和当前Request的内容编码.而Http内容的压缩其实是 ...