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 ...
随机推荐
- (十进制高速幂+矩阵优化)BZOJ 3240 3240: [Noi2013]矩阵游戏
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=3240 3240: [Noi2013]矩阵游戏 Time Limit: 10 Sec M ...
- win32 Service memory leak
https://stackoverflow.com/questions/2728578/how-to-get-phyiscal-path-of-windows-service-using-net ht ...
- 制作ubuntu的U盘启动盘
在制作U盘启动盘之前,请各位先格式化你的U盘. 制作U盘启动盘的工具有很多种,我们这里为大家介绍的是用软碟通制作.所有我们需要有这个软件,如果大家没有可以百度“软碟通”,下载安装一个.然后点击打开.在 ...
- Android系统自适应屏幕大小
1.屏幕相关概念1.1分辨率是指屏幕上有横竖各有多少个像素1.2屏幕尺寸指的是手机实际的物理尺寸,比如常用的2.8英寸,3.2英寸,3.5英寸,3.7英寸android将屏幕大小分为四个级别(smal ...
- DB2load遇到SQL3508N错误
SQL3508N装入或装入查询期间,当存取类型为 "<文件类型>" 的文件或路径时出错.原因码:"<原因码>".路径:"< ...
- c#制作简单启动画面的方法
本文实例讲述了c#制作简单启动画面的方法.分享给大家供大家参考.具体分析如下: 启动画面是程序启动加载组件时一个让用户稍微耐心等待的提示框.一个好的软件在有启动等待需求时必定做一个启动画面.启动画面可 ...
- 解决从Excel导入数据库,导入到DataTable时数据类型发生变化的问题(如数字类型变成科学计数法,百分数变成小数)
做项目的时候,C#读取Excel数据到DataTable或者DataSet,设断点查看DataTable,发现Excel的显示为较长位数数字的字段如0.000012在DataTable中显示为科学计数 ...
- Arduino扫盲(持续添加中)
1.Arduino火的很,很大一点在于,他基本透明掉了硬件电子部分,只剩下软件部分,通过把电子部分包装成黑箱,使得大量IT人士,普通人,甚至小学生也能玩的来. 2 .Arduino是一个电子原型开发平 ...
- ActiveMQ启动异常
启动报错信息:BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ...
- [转] hadoop MapReduce实例解析-非常不错,讲解清晰
来源:http://blog.csdn.net/liuxiaochen123/article/details/8786715?utm_source=tuicool 2013-04-11 10:15 4 ...