HDU 1069&&HDU 1087 (DP 最长序列之和)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
System Crawler (2015-11-18)
Description
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
Sample Input
Sample Output
10
3
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
int value[maxn];
int dp[maxn];
int main(){
int n;
//scanf("%d",&n);
while(scanf("%d",&n)!=EOF){
if(n==)
break;
for(int i=;i<=n;i++){
scanf("%d",&value[i]);
dp[i]=value[i];
}
int ans=-;
for(int i=;i<=n;i++){
for(int j=;j<i;j++){
if(value[i]>value[j]&&dp[i]<dp[j]+value[i])
dp[i]=dp[j]+value[i]; }
ans=max(ans,dp[i]);
}
printf("%d\n",ans);
}
return ;
}
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
prayerhgq (2015-08-04)
System Crawler (2015-11-23)
Description
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two of its three dimensions determined the dimensions of the base and the other dimension was the height.
They want to make sure that the tallest tower possible by stacking blocks can reach the roof. The problem is that, in building a tower, one block could only be placed on top of another block as long as the two base dimensions of the upper block were both strictly smaller than the corresponding base dimensions of the lower block because there has to be some space for the monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job is to write a program that determines the height of the tallest tower the monkey can build with a given set of blocks.
Input
representing the number of different blocks in the following data set. The maximum value for n is 30.
Each of the next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
Output
Sample Input
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=;
struct node{
int x,y,z;
}dp[maxn];
bool cmp(const struct node t1,const struct node t2){
if(t1.x!=t2.x)
return t1.x<t2.x;
return t1.y<t2.y;
}
int main(){
int cas=;
int n;
while(scanf("%d",&n)!=EOF){
int cnt=;
if(n==)
break;
int tx,ty,tz;
for(int i=;i<=n;i++){
scanf("%d%d%d",&tx,&ty,&tz);
dp[cnt].x=tx,dp[cnt].y=ty,dp[cnt].z=tz,cnt++;
dp[cnt].x=tx,dp[cnt].y=tz,dp[cnt].z=ty,cnt++;
dp[cnt].x=ty,dp[cnt].y=tx,dp[cnt].z=tz,cnt++;
dp[cnt].x=ty,dp[cnt].y=tz,dp[cnt].z=tx,cnt++;
dp[cnt].x=tz,dp[cnt].y=tx,dp[cnt].z=ty,cnt++;
dp[cnt].x=tz,dp[cnt].y=ty,dp[cnt].z=tx,cnt++;
}
sort(dp,dp+cnt,cmp); for(int i=;i<cnt;i++){
int tmp=-;
for(int j=;j<i;j++){
if((((dp[i].x>dp[j].x)&&(dp[i].y>dp[j].y))||((dp[i].x>dp[j].y)&&(dp[i].y>dp[j].x)))&&(dp[j].z>tmp)){
tmp=dp[j].z;
}
}
if(tmp!=-)
dp[i].z+=tmp;
}
int ans=-;
for(int i=;i<cnt;i++){
ans=max(ans,dp[i].z); } printf("Case %d: maximum height = %d\n",cas++,ans);
}
return ;
}
HDU 1069&&HDU 1087 (DP 最长序列之和)的更多相关文章
- HDU 4607 Park Visit (DP最长链)
[题目]题意:N个城市形成一棵树,相邻城市之间的距离是1,问访问K个城市的最短路程是多少,共有M次询问(1 <= N, M <= 100000, 1 <= K <= N). [ ...
- HDU 1069 Monkey and Banana(最长递减子序列)
题目链接 题意:摞长方体,给定长方体的长宽高,个数无限制,可随意翻转,要求下面的长方体的长和宽都大于上面的,都不能相等,问最多能摞多高. 题解:个数无限,其实每种形态最多就用一次,把每种形态都单独算一 ...
- HDU 1069 dp最长递增子序列
B - Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- HDU 1069—— Monkey and Banana——————【dp】
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana dp 题解
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种 ...
- 怒刷DP之 HDU 1069
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana (DP)
Monkey and Banana Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- hdu 1025 dp 最长上升子序列
//Accepted 4372 KB 140 ms //dp 最长上升子序列 nlogn #include <cstdio> #include <cstring> #inclu ...
随机推荐
- 实现一个基于WCF的分布式缓存系统
tks:http://www.cnblogs.com/xiguain/p/3913220.html
- 第二十五课:jQuery.event.trigger的源码解读
本课主要来讲解jQuery.event.trigger的源码解读. trigger = function(event, data, elem, onlyHandlers){ if(elem & ...
- [设计模式]第三回:抽象工厂模式(Abstract Factory)
概述 在系统中往往会有这种需求,客户端会用到很多对象,而且根据需求变化很可能会切换成另外一套对象.抽象工厂模式可以提供一种封装机制来面对这种需求. 实践 物理模型: 皮肤主题:设计一个可以切换皮肤主题 ...
- iOS边练边学--父子控件之作为导航控制器的子类产生的问题以及网易新闻练习
一.导航控制器的子类 作为导航控制器的子类,并且是导航控制器子类中的第一个,系统会默认给子控件添加EdgeInsert属性,把导航栏的宽度挤出来.但是系统只会默认修改第一个. 解决办法1:系统帮忙给第 ...
- Cas_个人理解
分为三个部分: 1.Cas服务器(用于验证用户是否正确) 1.用户信息存在服务端,其它客户端应用程序修改用户信息后需要同步到服务端 2.用户信息一般存储在服务端的数据 ...
- 【BZOJ 1013】【JSOI2008】球形空间产生器sphere 高斯消元基础题
最基础的高斯消元了,然而我把j打成i连WA连跪,考场上再犯这种错误就真的得滚粗了. #include<cmath> #include<cstdio> #include<c ...
- opencv笔记1:opencv的基本模块,以及环境搭建
opencv笔记1:opencv的基本模块,以及环境搭建 安装系统 使用fedora22-workstation-x86_64 安装opencv sudo dnf install opencv-dev ...
- KMP 算法总结
KMP算法是基本的字符串匹配算法,但是代码实现上有一些细节容易错.这篇随笔将认真总结一下. KMP算法的核心是: The KMP algorithm searches for occurrences ...
- leach-matlab
http://www.oschina.net/code/snippet_860036_21044 clear;%清除变量 xm=100;%设置区域为100*100 ym=100; sink.x=0.5 ...
- 网络html查看器
1)演示效果: