[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 ...
随机推荐
- Android 手机上安装并运行 Ubuntu 12.04
ubuntu.sh脚本的原地址变动了,导致下载不了,现在更新了网盘地址.小技巧:遇到一些下载失效的时候可以试一试p2p下载工具(如 easyMule.迅雷等)试一试,说不定有人分享过~* —————— ...
- xcode6编译cocos2dx项目出现Undefined symbols _fwrite$UNIX2003
当xcode6编译cocos2dx的时候会出现Undefined symbols _fwrite$UNIX2003 这个问题.google了一篇文章:http://stackoverflow.com/ ...
- Android 学习开发笔记《Service 与 Thread 的区别 》
很多时候,你可能会问,为什么要用 Service,而不用 Thread 呢,因为用 Thread 是很方便的,比起 Service 也方便多了,下面我详细的来解释一下. 1). Thread:Thre ...
- HTTP协议头部与Keep-Alive模式详解
HTTP协议头部与Keep-Alive模式详解 .什么是Keep-Alive模式? 我们知道HTTP协议采用“请求-应答”模式,当使用普通模式,即非KeepAlive模式时,每个请求/应答客户和服务器 ...
- bzoj 1007 : [HNOI2008]水平可见直线 计算几何
题目链接 给出n条直线, 问从y轴上方向下看, 能看到哪些直线, 输出这些直线的编号. 首先我们按斜率排序, 然后依次加入一个栈里面, 如果刚加入的直线, 和之前的那条直线斜率相等, 那么显然之前的会 ...
- SpringMVC之访问静态文件
我们在进行springMVC开发时,必定会在jsp页面引入js文件.img文件和css文件.大多数人会将这些分类存放在WebRoot文件下新建的文件夹下面.同时,会在web.xml文件中配置拦截所有请 ...
- 转:PAT练习题概览
AT(pat.zju.edu.cn)是一个面向 C/C++程序的 Online Judge 系统.相比 ZOJ,HDOJ,POJ 等 ACM 题库,PAT 的题目非常基础,对于数据结构.算法的入门是比 ...
- UIControl IOS控件编程 及UITextField的讲解
第一部分 UIKit提供了一组控件:UISwitch开关.UIButton按钮.UISegmentedControl分段控件.UISlider滑块.UITextField文本字段控件.UIPageCo ...
- OS之多线程
os中引入进程的目的是,为了描述和实现多个程序的并发执行,以改善资源利用率及提高系统的吞吐量. 为什么要引入线程?这是为了减少程序并发执行时系统所付出的额外开销(堆栈切换的开销等),使os具有更好的并 ...
- JS 排列组合
function $CL(arr, n, noLC, arrDan) { //从arr中取n个组合,然后 var r = [], sum = 0; n = n - arrDan.length; (fu ...