poj2181 jumping cow
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7579 | Accepted: 4559 |
Description
The local witch doctor has mixed up P (1 <= P <= 150,000) potions to aid the cows in their quest to jump. These potions must be administered exactly in the order they were created, though some may be skipped.
Each potion has a 'strength' (1 <= strength <= 500) that enhances the cows' jumping ability. Taking a potion during an odd time step increases the cows' jump; taking a potion during an even time step decreases the jump. Before taking any potions the cows' jumping ability is, of course, 0.
No potion can be taken twice, and once the cow has begun taking potions, one potion must be taken during each time step, starting at time 1. One or more potions may be skipped in each turn.
Determine which potions to take to get the highest jump.
Input
* Lines 2..P+1: Each line contains a single integer that is the strength of a potion. Line 2 gives the strength of the first potion; line 3 gives the strength of the second potion; and so on.
Output
Sample Input
8
7
2
1
8
4
3
5
6
Sample Output
17 简单dp,设f[i][0]表示选了到i个,用完奇数时间的最大值,f[i][1]表示选到第i个,用完偶数时间的最大值,转移方程显而易见。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
int a[];
int f[][];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int now=;
bool hh=;
for(int i=;i<=n;i++)
{
hh^=;
f[hh][]=max(f[hh^][],f[hh^][]+a[i]);
f[hh][]=max(f[hh^][]-a[i],f[hh^][]);
}
cout<<max(f[hh][],f[hh][]);
//system("pause");
}
poj2181 jumping cow的更多相关文章
- POJ-2181 Jumping Cows(贪心)
Jumping Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7329 Accepted: 4404 Descript ...
- Jumping Cows_贪心
Description Farmer John's cows would like to jump over the moon, just like the cows in their favorit ...
- Cow Hopscotch
Cow Hopscotch 题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have inv ...
- Luogu P2888 [USACO07NOV]牛栏Cow Hurdles
题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gan ...
- 【BZOJ3939】[Usaco2015 Feb]Cow Hopscotch 动态规划+线段树
[BZOJ3939][Usaco2015 Feb]Cow Hopscotch Description Just like humans enjoy playing the game of Hopsco ...
- 洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles
题目戳 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the ...
- OJ 21651::Cow Hurdles(佛罗一德的变式)
Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and ...
- 洛谷P3120 [USACO15FEB]Cow Hopscotch
题目描述 Just like humans enjoy playing the game of Hopscotch, Farmer John's cows have invented ...
- POJ 2181 Jumping Cows
Jumping Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6398 Accepted: 3828 Desc ...
随机推荐
- (B)springboot配置开发和测试环境并添加启动路径
嗯,开发和测试环境要分离,这是一般共识(虽然我工作过的公司都没有这种分离),spring boot也可以按照配置文件的读取来做到这一点. 上图有三个application开头的配置文件,要达到能够读取 ...
- USACO Section2.2 Runaround Numbers 解题报告 【icedream61】
runround解题报告---------------------------------------------------------------------------------------- ...
- Kotlin将Realm提升到更高层次
作者:Víctor Manuel Pineda 时间:Feb 14, 2017 原文链接:https://antonioleiva.com/kotlin-realm-extensions/ 当有人问我 ...
- [译]17-spring基于java代码的配置元数据
spring还支持基于java代码的配置元数据.不过这种方式不太常用,但是还有一些人使用.所以还是很有必要介绍一下. spring基于java代码的配置元数据,可以通过@Configuration注解 ...
- Linux静态ip设置及一些网络设置
网络服务配置文件 /etc/sysconfig/network 网络接口配置文件 /etc/sysconfig/network-scripts/ifcfg-INTERFACE_NAME 修改IP永久生 ...
- 普通用户操作tomcat项目时报:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environment variable is needed to run this program
在使用普通用户更新tomcat项目适合出现这个信息,Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At ...
- 史林枫:sqlserver数据库中数据日志的压缩及sqlserver占用内存管理设置
使用sqlserver和IIS开发.net B/S程序时,数据量逐渐增多,用户也逐渐增多,那么服务器的稳定性就需要维护了.数据库如何占用更小内存,无用的日志如何瞬间清空? 今天在给一个客户维护网站的时 ...
- atan与atan2的区别
相比较ATan,ATan2究竟有什么不同?本篇介绍一下ATan2的用法及使用条件. 对于tan(θ) = y / x: θ = ATan(y / x)求出的θ取值范围是[-PI/2, PI/2]. θ ...
- 【转】oracle 删除重复记录
转至:http://blog.163.com/aner_rui/blog/static/12131232820105901451809/ 2.保留一条(这个应该是大多数人所需要的 ^_^) Delet ...
- 动态规划DP的斜率优化 个人浅解 附HDU 3669 Cross the Wall
首先要感谢叉姐的指导Orz 这一类问题的DP方程都有如下形式 dp[i] = w(i) + max/min(a(i)*b(j) + c(j)) ( 0 <= j < i ) 其中,b, c ...