[Swust OJ 893]--Blocks
题目链接:http://acm.swust.edu.cn/problem/893/
Josh loves playing with blocks. Currently, he has N blocks, labeled 0 through N-1. The heights of all blocks are positive integers. More precisely, for each i, the height of block i is blockHeights[i]. Josh is interested in making the tallest block tower possible. He likes all his towers to follow three simple rules:
1.The blocks must be stacked in a single column, one atop another. The height of the tower is simply the sum of heights of all its blocks.
2.The labels of blocks used in the tower must increase from the bottom to the top. In other words, whenever Josh places box x on top of box y, we have x > y.
3.Josh will never place a box of an even height on top of a box of an odd height.
you need find out the height of the tallest possible block tower Josh can build.
Each test case starts with a number N (0 < N <= 1000000) -- the total number of blocks,followed by N positive numbers.All the numbers in the input are less than 1000.A test case with N = 0 denotes the end of input. This test case is not to be processed.
Print the tallest possible block tower on a single line for each test case.
1
2
3
4
5
6
|
2
4 7
2
7 4
5
49 2 49 2 49
|
1
2
3
|
11
7
147
|
#include <stdio.h>
int dp[][];
#define max(a,b) a>b?a:b
int main()
{
int n, height, i;
while (~scanf("%d", &n), n){
for (i = ; i < n; i++){
scanf("%d", &height);
if (height & ){
if (!i){
dp[i][] = height;
dp[i][] = ;
}
else{
dp[i][] = max(dp[i - ][] + height, dp[i - ][] + height);
dp[i][] = dp[i - ][];
}
}
else{
if (!i){
dp[i][] = height;
dp[i][] = ;
}
else{
dp[i][] = dp[i - ][] + height;
dp[i][] = dp[i - ][];
}
}
}
printf("%d\n", max(dp[n - ][], dp[n - ][]));
}
return ;
}
[Swust OJ 893]--Blocks的更多相关文章
- [Swust OJ 404]--最小代价树(动态规划)
题目链接:http://acm.swust.edu.cn/problem/code/745255/ Time limit(ms): 1000 Memory limit(kb): 65535 Des ...
- [Swust OJ 649]--NBA Finals(dp,后台略(hen)坑)
题目链接:http://acm.swust.edu.cn/problem/649/ Time limit(ms): 1000 Memory limit(kb): 65535 Consider two ...
- SWUST OJ NBA Finals(0649)
NBA Finals(0649) Time limit(ms): 1000 Memory limit(kb): 65535 Submission: 404 Accepted: 128 Descri ...
- [Swust OJ 1023]--Escape(带点其他状态的BFS)
解题思路:http://acm.swust.edu.cn/problem/1023/ Time limit(ms): 5000 Memory limit(kb): 65535 Descript ...
- [Swust OJ 1125]--又见GCD(数论,素数表存贮因子)
题目链接:http://acm.swust.edu.cn/problem/1125/ Time limit(ms): 1000 Memory limit(kb): 65535 Descriptio ...
- [Swust OJ 1126]--神奇的矩阵(BFS,预处理,打表)
题目链接:http://acm.swust.edu.cn/problem/1126/ Time limit(ms): 1000 Memory limit(kb): 65535 上一周里,患有XX症的哈 ...
- [Swust OJ 1026]--Egg pain's hzf
题目链接:http://acm.swust.edu.cn/problem/1026/ Time limit(ms): 3000 Memory limit(kb): 65535 hzf ...
- [Swust OJ 1139]--Coin-row problem
题目链接: http://acm.swust.edu.cn/contest/0226/problem/1139/ There is a row of n coins whose values are ...
- [Swust OJ 385]--自动写诗
题目链接:http://acm.swust.edu.cn/problem/0385/ Time limit(ms): 5000 Memory limit(kb): 65535 Descripti ...
随机推荐
- PHP新手必须掌握的入门与实战技巧
作为当今主流的开发语言,PHP集简单.免费.高效等特点于一身.对于想加入PHP大军的新手来说,从何学起.如何学习? 你需要掌握PHP的基础知识.常用功能模块.面向对象.MVC等相关技能.学会了这些技能 ...
- Could not load type System.ServiceModel.Activation.HttpModule解决办法
等注册完成后网站就可以打开了. win2008下提示未能从程序集“System.ServiceModel, Version=3.0.0.0问题解决 在Windows Server 2008中的IIS服 ...
- Cyclomatic complexity
Cyclomatic Code Complexity was first introduced by Thomas McCabe in 1976. In 1976, Thomas McCabe pub ...
- web 性能优化指南阅读笔记
1.关于拥塞预防算法 PRR-比例降速,RFC6937 规定的一个新算法,其目标是改进丢包后的恢复速度,谷歌测量结果:该算法改进丢包造成的平均连接延迟减少了3%-10%.PRR是linux 3.2+内 ...
- MVC-04 视图(1)
不可否认的,View应该是整个ASP.NET MVC项目开发过程中最花时间的部分,因为与显示逻辑相关的技术五花八门,你可能要学习的有HTML.CSS.JavaScript.DOM.JQuery.JSO ...
- ISO14443 ISO15693 ISO18000
[提要]射频标签的通信标准是标签芯片设计的依据,目前国际上与RFID相关的通信标准主要有:ISO/IEC 18000标准(包括7个部分,涉及125KHz, 13.56MHz, 433MHz, 860- ...
- 提高你的Java代码质量吧:使用valueof前必须进行校验
一.分析 每个枚举都是java.lang.Enum的子类,都可以访问Enum类提供的方法,比如hashCode.name.valueOf等,其中valueOf方法会把一个String类型的名称转变成枚 ...
- 具体解释coredump
一,什么是coredump 我们常常听到大家说到程序core掉了,须要定位解决,这里说的大部分是指相应程序因为各种异常或者bug导致在执行过程中异常退出或者中止,而且在满足一定条件下(这里为什么说须要 ...
- swt combo 自动补全
public class AutoCompleteComboMain { static final Display display = new Display(); static fi ...
- python字符串格式化符号含义及转义字符含义
字符串格式化符号含义 符 号 说 明 %c 格式化字符及其ASCII码 %s 格式化字符串 %d 格式化整数 %o ...