Apple Catching
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13447   Accepted: 6549

Description

It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. However, she must catch them in the air since the apples bruise when they hit the ground (and no one wants to eat bruised apples). Bessie is a quick eater, so an apple she does catch is eaten in just a few seconds.

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

* Line 1: Two space separated integers: T and W

* Lines 2..T+1: 1 or 2: the tree that will drop an apple each minute.

Output

* Line 1: The maximum number of apples Bessie can catch without walking more than W times.

Sample Input

7 2
2
1
1
2
2
1
1

Sample Output

6

Hint

INPUT DETAILS:

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

 
 
 
------------------------------------------------------------------------------------
分析:用dp[i][j]表示时间 i 时 跑了 j 次的最大苹果数。然后。如果dp[i][j]这时正好有一颗苹果,则dp[i][j]++

  还要预处理一下。

 #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)的更多相关文章

  1. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  2. 【POJ】3616 Milking Time(dp)

    Milking Time Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10898   Accepted: 4591 Des ...

  3. 【BZOJ】1068: [SCOI2007]压缩(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1068 发现如果只设一维的话无法转移 那么我们开第二维,发现对于前i个来说,如果确定了M在哪里,第i个 ...

  4. 【POJ】2234 Matches Game(博弈论)

    http://poj.org/problem?id=2234 博弈论真是博大精深orz 首先我们仔细分析很容易分析出来,当只有一堆的时候,先手必胜:两堆并且相同的时候,先手必败,反之必胜. 根据博弈论 ...

  5. 【51nod1519】拆方块[Codeforces](dp)

    题目传送门:1519 拆方块 首先,我们可以发现,如果第i堆方块被消除,只有三种情况: 1.第i-1堆方块全部被消除: 2.第i+1堆方块全部被消除:(因为两侧的方块能够保护这一堆方块在两侧不暴露) ...

  6. 【bzoj1925】地精部落[SDOI2010](dp)

    题目传送门:1925: [Sdoi2010]地精部落 这道题,,,首先可以一眼看出他是要我们求由1~n的排列组成,并且抖来抖去的序列的方案数.然后再看一眼数据范围,,,似乎是O(n^2)的dp?然后各 ...

  7. 【ZOJ2278】Fight for Food(dp)

    BUPT2017 wintertraining(16) #4 F ZOJ - 2278 题意 给定一个10*10以内的地图,和p(P<=30000)只老鼠,给定其出现位置和时间T(T<=1 ...

  8. 【vijos】1764 Dual Matrices(dp)

    https://vijos.org/p/1764 自从心态好了很多后,做题的确很轻松. 这种题直接考虑我当前拿了一个,剩余空间最大能拿多少即可. 显然我们枚举每一个点拿出一个矩形(这个点作为右下角), ...

  9. 【Luogu】P3856公共子串(DP)

    题目链接 DP.设last[i][j]是第i个串字符'j'所在的最后的位置,f[i][j][k]是第一个串匹配到i,第二个串匹配到j,第三个串匹配到k,最多的公共子串数. 那么我们三重循环i.j.k, ...

随机推荐

  1. continue的作用

    特别有用,用于循环中-跳过不满足某个条件的某轮循环continue后面的语句

  2. Android敏捷开发、CI(持续集成)探究

    比较老的几篇文章,依旧有学习价值 http://blog.csdn.net/baodinglaolang/article/details/9530695 http://blog.csdn.net/ba ...

  3. SSH项目搭建(二)

    本章讲解SSH项目需要到哪些jar包,及各个jar包的作用 一.struts2 1.下载好struts2,struts2文件夹>>>>apps>>>>a ...

  4. HDU 2273

    http://acm.hdu.edu.cn/showproblem.php?pid=2273 N辆车排队过马路,不能相撞,问最短时间 ans=车的总长度/最小速度 #include <iostr ...

  5. selenium python实例脚本1

    #!/usr/local/bin/python3 # coding=utf-8 #统一编码from selenium import webdriverfrom time import sleep#im ...

  6. Scoi 2010 幸运数字

    [题目描述]在中国,很多人都把6和8视为是幸运数字!lxhgww也这样认为,于是他定义自己的“幸运号码”是十进制表示中只包含数字6和8的那些号码,比如68,666,888都是“幸运号码”!但是这种“幸 ...

  7. Python学习-lambda表达式

    lambda只是一个表达式,函数体比def简单很多.lambda的主体是一个表达式,而不是一个代码块.仅仅能在lambda表达式中封装有限的逻辑进去.lambda表达式是起到一个函数速写的作用.允许在 ...

  8. Python学习-赋值、浅copy和深copy

    Python Copy: 在Python语言中,分为浅拷贝和深拷贝两种形式,也就是官方文档中的Shadow copy和Deep copy.在对简单的对象(object)进行复制时,两者没有区别,如下面 ...

  9. 《DSP using MATLAB》示例 Example 6.14、6.15

  10. Java 按行拆分txt

    T028619630|@|聚二零|@|M|@|1983-01-01|@|0|@|110101198301010098|@||@||@||@|湖南省衡阳市耒阳市蔡伦步行街1005号302|@|42100 ...