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

#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int dp[][];
int apple[];
int main(){
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
cin>>apple[i];
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
if(j==){
dp[i][j]=dp[i-][j];
}
else{
dp[i][j]=max(dp[i-][j],dp[i-][j-]);
}
if(j%+==apple[i])
dp[i][j]++;
}
}
int ans=dp[n][];
for(int i=;i<=m;i++){
if(ans<dp[n][i])
ans=dp[n][i];
}
cout<<ans<<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【动态规划】

    Description It is a little known fact that cows love apples. Farmer John has two apple trees (which ...

  4. poj2385 Apple Catching(dp状态转移方程推导)

    https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人 ...

  5. poj2385 Apple Catching

    思路: 简单dp. 实现: #include <iostream> #include <cstdio> #include <cstring> using names ...

  6. 【POJ - 2385】Apple Catching(动态规划)

    Apple Catching 直接翻译了 Descriptions 有两棵APP树,编号为1,2.每一秒,这两棵APP树中的其中一棵会掉一个APP.每一秒,你可以选择在当前APP树下接APP,或者迅速 ...

  7. Apple Catching(POJ 2385)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9978   Accepted: 4839 De ...

  8. Apple Catching(dp)

    Apple Catching Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9831   Accepted: 4779 De ...

  9. 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 ...

  10. 3384/1750: [Usaco2004 Nov]Apple Catching 接苹果

    3384/1750: [Usaco2004 Nov]Apple Catching 接苹果 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 18  Solv ...

随机推荐

  1. 将文件中的内容读取到map中,并排除不需要的关键字然后输出

  2. Jsonpath的基本使用

    JSONPath - 是xpath在json的应用. xml最大的优点就有大量的工具可以分析,转换,和选择性的提取文档中的数据.XPath是这些最强大的工具之一.   如果可以使用xpath来解析js ...

  3. 12. pt-index-usage

    pt-index-usage h=192.168.100.101,P=3306,u=admin,p=admin /data/mysql3306/data/slow.log 根据slow log来判断i ...

  4. qt 5.2.1类和模块的关系图

    QT│  ├─ActiveQt│  │  ActiveQt│  │  ActiveQtDepends│  │  ActiveQtVersion│  │  QAxAggregated│  │  QAxB ...

  5. Spring Boot REST(一)核心接口

    Spring Boot REST(一)核心接口 Spring 系列目录(https://www.cnblogs.com/binarylei/p/10117436.html) SpringBoot RE ...

  6. servlet 高级知识之Filter

    Filter叫做拦截器, 对目标资源拦截,拦截HTTP请求和HTTP响应,本质是对url进行拦截. 与serlvet不同的是, Filter的初始化是随着服务器启动而启动. 在Filter接口中定义了 ...

  7. Rigidbody.Is Kinematic和碰撞体

    Rigidbody组件拥有一个Is Kinematic的属性,该属性可以将其从引擎的控制中移除,从而可以用脚本控制GO的运动.注意:尽量不要使用脚本控制该属性的开关. Colliders(碰撞器) C ...

  8. Django的学习(二)————Templates

    一.django的模板: 在settings.py的文件中可以看到并设置这个模板. 1.直接映射: 通过建立的文件夹(templates)和文件(html)来映射. <!DOCTYPE html ...

  9. 2019.01.20 bzoj3784: 树上的路径(二分答案+点分治)

    传送门 点分治好题. 题意简述:给一棵带边权的树,问所有路径中前mmm大的.m≤300000m\le300000m≤300000 思路: 网上有题解写了可以通过什么点分治序转化成超级钢琴那道题的做法蒟 ...

  10. 2018.11.01 bzoj4325: NOIP2015 斗地主(贪心+搜索)

    传送门 原来一直以为是一道大模拟. 没想到是一道搜索+最优性剪枝 如何搜最优呢? 我们考虑怎么最快出完. 大概是应该尽量出当前能出出去最多的吧. 于是我们选择优先出顺子. 这样做有什么好处呢? 我们会 ...