[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 ...
随机推荐
- mybatis一对一关联表查询
先创建一个表 CREATE TABLE teacher( t_id INT PRIMARY KEY AUTO_INCREMENT, t_name ) ); CREATE TABLE class( c_ ...
- Nginx工作原理和优化、漏洞(转)
查看安装了哪些模块命令: [root@RG-PowerCache-X xcache]# nginx/sbin/nginx -Vnginx version: nginx/1.2.3built by gc ...
- 基于Visual C++2013拆解世界五百强面试题--题14-循环删除
有一个数组a[1000]存放0-1000,要求每隔二个数删除一个数,到末尾时循环到开头继续进行,求最后一个被删掉数的原始下标. 看到题目可以用循环链表保存这些数,然后循环删除,大大减少了一些复杂的边界 ...
- 【剑指Offer学习】【面试题36:数组中的逆序对】
题目:在数组中的两个数字假设前面一个数字大于后面的数字.则这两个数字组成一个逆序对.输入一个数组.求出这个数组中的逆序对的总数. 举例分析 比如在数组{7, 5, 6, 4 中, 一共存在5 个逆序对 ...
- HDU4451Dressing(计数)
HDU4451Dressing(计数) 题目链接 题目大意:给你N件衣服, M条裤子, K双鞋子,如今有P个不合理的的搭配(衣服和裤子或者裤子和鞋子),要求不用P中不理的搭配方式来将衣服裤子鞋子三件搭 ...
- c 围圈报数
#include<stdio.h> /*围圈报数*/ void left(int *p,int m,int n) { int i,j,count; i = j = count = ; ) ...
- View中的onTouchEvent()与setOnTouchListener()中的ontouch()方法的事件处理先后顺序
Touch事件的两种情况 1.覆写View.class中定义的onTouchEvent-->基于事件回调监听方式 @Override public boolean onTouchEvent(Mo ...
- Qualified name lookup
Qualified name lookup Qualified name lookup Enumerations Class members Namespace members Unqualified ...
- NSUserDefaults概述
原创,转载请注明原文:NSUserDefaults概述 By Lucio.Yang 首先,iOS中有四种存储数据的方式-对比iOS中的四种数据存储 NSUserDefaults是其中很常用的一种.N ...
- django开发简易博客(四)
上一节,我们讲述了怎么使用静态文件,并使用bootstrap对页面进行了美化,这一节我们将增强我们blog的功能,添加发表博客,删除博客的功能. 一.表单的使用 要实现添加blog的功能,就得使用表单 ...