poj2385(dp)
题目链接:http://poj.org/problem?id=2385
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 9372 | Accepted: 4565 |
Description
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
* 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 <iostream>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define ll long long
const double eps = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007; int t,w,x;
int f[1005][35],a[1005]; int main ()
{
while (scanf ("%d%d",&t,&w)==2)
{
memset(f, 0,sizeof(f));
for (int i=1; i<=t; i++)
{
scanf ("%d",&a[i]);
f[i][0] = f[i-1][0]+(a[i]==1?1:0);
}
for (int j=1; j<=w; j++)
{
for (int i=1; i<=t; i++)
{
f[i][j] = max(f[i-1][j], f[i-1][j-1])+(a[i]==(j%2+1)?1:0);
}
}
printf ("%d\n",f[t][w]);
}
return 0;
}
poj2385(dp)的更多相关文章
- poj2385 dp(递推)
题目链接 :http://bak3.vjudge.net/contest/136499#problem/D 题意: //转移方程dp[i][j]=max(dp[i-1][j],dp[i-1][j-1] ...
- poj2385 Apple Catching(dp状态转移方程推导)
https://vjudge.net/problem/POJ-2385 猛刷简单dp的第一天的第一题. 状态:dp[i][j]表示第i秒移动j次所得的最大苹果数.关键要想到移动j次,根据j的奇偶判断人 ...
- poj2385 简单DP
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:65536KB 64bit ...
- DP,得到最多苹果,(POJ2385)
题目链接:http://poj.org/problem?id=2385 题意: 牛在两棵苹果树下收集苹果,牛只能在这两棵树之间走动w次,在t时刻,某棵树会掉下苹果. 解题报告: ///dp[t][w] ...
- poj2385【基础DP】
挑战DP 题意: 有两棵树,给每分钟有苹果掉落的苹果树,一开始B在 1 树下,B最多只能移动W步,求一个最大数量拿到的. 思路: 一开始想的是,我对于每分钟情况来说无非是等于之前的在本位置+1,或者等 ...
- poj2385(基础DP)
题目链接:http://poj.org/problem?id=2385 题意:最开始Bessie站在树1下面,每一个单位时间有颗苹果从树1或者树2上落下来.每个单位时间Bessie可以移动一次位置,时 ...
- poj2385 Apple Catching (线性dp)
题目传送门 Apple Catching Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 154 ...
- BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]
1911: [Apio2010]特别行动队 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 4142 Solved: 1964[Submit][Statu ...
- 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...
随机推荐
- MySQL官方文档
http://dev.mysql.com/doc/refman/5.7/en/index.html 没有比这更好的MySQL文档了,省的去买书了
- Hadoop自学笔记(二)HDFS简单介绍
1. HDFS Architecture 一种Master-Slave结构.包括Name Node, Secondary Name Node,Data Node Job Tracker, Task T ...
- cocos2dx --- 在游戏中显示HTML页面
前文介绍了简单的富文本组件RichText,如今我们来了解下由freeType库做出来的第三方组件.可以直接显示html页面,而且可以实现超链接.和触摸事情. 步骤: 1.在github中 下载 ...
- 转:Java修改Excel单元格的数据及格式
https://blog.csdn.net/aking21alinjuju/article/details/6001153?locationNum=2 继前两节的Java读取.写入Excel后,本期将 ...
- Java中Array、List、Set、Map
一.Java中数组 数组用来存放固定数量的同类元素,声明方法: T[] ref,T ref[],如int[] intAry; int intAry[].推荐用T[]的方式,后一种方式为兼容C++习惯写 ...
- 欢迎来到Flask的世界
不多说,直接上文档链接:Flask的文档 教程 API 快速上手
- CheckBox的Attributes
在看老同事写的代码的时候,发现了这样的一段代码:之前自己没有遇到过,记录下吧. 大致是这样的 foreach (GridViewRow grv in GridView1.Rows) { CheckBo ...
- CDR 2017压感笔和压感设备该怎么设置使用?
您可以通过CorelDRAW 2017 中的以下工具来运用压感笔.笔或其他设备的压力:艺术笔(表达模式).橡皮擦.涂抹.转动.吸引.排斥.粗糙和弄脏.此外,您还可以通过艺术笔(表达模式)工具.橡皮擦. ...
- Pyhton学习——Day31
# 服务端和接收端的send和reve没有任何关系,只与协议之间有关系# 应用程序产生的数据一定会交给操作系统,并由操作系统往外发送# 发送端什么时候会清空自己的内存?# 收到接收端的ACK响应以后才 ...
- Android 7.0 Gallery图库源码分析1 - 初识Gallery源码
分析一个项目的源代码时,第一件事就是查看清单文件,找到程序入口,我们从Gallery2源码的清单文件中可以看到GalleryActivity是此应用的启动Activity. <activity ...