最长上升子序列(LIS经典变型) dp学习~5
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
Monkey and Banana
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10875 Accepted Submission(s): 5660
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.
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.
10 20 30
2
6 8 10
5 5 5
7
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
6 6 6
7 7 7
5
31 41 59
26 53 58
97 93 23
84 62 64
33 83 27
0
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342
题目:给出一些长方体,然后让你把他堆成塔,
要求下面的塔的要比上面的塔大(长和宽),
而且每一种长方体的数量都是无限的。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = ; struct Node {
int x;
int y;
int z;
bool operator < (const Node &a) const
{
if(x!=a.x) return x < a.x;
else if(y!=a.y) return y < a.y;
else return z > a.z;
}
} node[N];
int dp[N]; int main()
{
int n;
int cnt = ;
while(~scanf("%d",&n))
{
if(n==) return ;
memset(dp,,sizeof(dp));
int x,y,z;
int t = ;
for(int i = ; i < n; i++){
scanf("%d%d%d",&x,&y,&z);
node[t].x = x;
node[t].y = y;
node[t].z = z;
t++;
node[t].x = x;
node[t].y = z;
node[t].z = y;
t++;
node[t].x = y;
node[t].y = x;
node[t].z = z;
t++;
node[t].x = y;
node[t].y = z;
node[t].z = x;
t++;
node[t].x = z;
node[t].y = x;
node[t].z = y;
t++;
node[t].x = z;
node[t].y = y;
node[t].z = x;
t++;
}
sort(node,node+*n);
int mmax = ;
for(int i = ; i < *n; i++)
dp[i] = node[i].z;
for(int i = ; i < *n; i++)
{
for(int j = ; j < i; j++)
{
if((node[i].x>node[j].x)&&(node[i].y>node[j].y))
dp[i] = max(dp[i],dp[j]+node[i].z);
}
mmax = max(mmax,dp[i]);
}
printf("Case %d: maximum height = ",cnt);
cnt++;
printf("%d\n",mmax);
}
return ;
}
最长上升子序列(LIS经典变型) dp学习~5的更多相关文章
- AT2827 最长上升子序列LIS(nlogn的DP优化)
题意翻译 给定一长度为n的数列,请在不改变原数列顺序的前提下,从中随机的取出一定数量的整数,并使这些整数构成单调上升序列. 输出这类单调上升序列的最大长度. 数据范围:1<=n<=10 ...
- 1. 线性DP 300. 最长上升子序列 (LIS)
最经典单串: 300. 最长上升子序列 (LIS) https://leetcode-cn.com/problems/longest-increasing-subsequence/submission ...
- 动态规划(DP),最长递增子序列(LIS)
题目链接:http://poj.org/problem?id=2533 解题报告: 状态转移方程: dp[i]表示以a[i]为结尾的LIS长度 状态转移方程: dp[0]=1; dp[i]=max(d ...
- 最长上升子序列 LIS(Longest Increasing Subsequence)
引出: 问题描述:给出一个序列a1,a2,a3,a4,a5,a6,a7….an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1<s2<s3<…< ...
- 最长回文子序列LCS,最长递增子序列LIS及相互联系
最长公共子序列LCS Lintcode 77. 最长公共子序列 LCS问题是求两个字符串的最长公共子序列 \[ dp[i][j] = \left\{\begin{matrix} & max(d ...
- 最长上升子序列LIS(51nod1134)
1134 最长递增子序列 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出长度为N的数组,找出这个数组的最长递增子序列.(递增子序列是指,子序列的元素是递 ...
- 【部分转载】:【lower_bound、upperbound讲解、二分查找、最长上升子序列(LIS)、最长下降子序列模版】
二分 lower_bound lower_bound()在一个区间内进行二分查找,返回第一个大于等于目标值的位置(地址) upper_bound upper_bound()与lower_bound() ...
- 2.16 最长递增子序列 LIS
[本文链接] http://www.cnblogs.com/hellogiser/p/dp-of-LIS.html [分析] 思路一:设序列为A,对序列进行排序后得到B,那么A的最长递增子序列LIS就 ...
- 题解 最长上升子序列 LIS
最长上升子序列 LIS Description 给出一个 1 ∼ n (n ≤ 10^5) 的排列 P 求其最长上升子序列长度 Input 第一行一个正整数n,表示序列中整数个数: 第二行是空格隔开的 ...
- 一个数组求其最长递增子序列(LIS)
一个数组求其最长递增子序列(LIS) 例如数组{3, 1, 4, 2, 3, 9, 4, 6}的LIS是{1, 2, 3, 4, 6},长度为5,假设数组长度为N,求数组的LIS的长度, 需要一个额外 ...
随机推荐
- Wincc flexable的数据记录的组态
1.数据记录就是将PLC采集的数据记录下来如下,注意只有TP270和OP270以上的HMI设备才有数据记录 2.练习展示 3.开始创建数据记录 4.组态数据记录 5.组态变量的记录属性.将数据记录和变 ...
- Java中 &&与&,||与|的区别
区别 && || 是逻辑运算,支持短路运算 & | 是位运算,不支持短路运算 短路运算 当有多个表达式时,左边的表达式值可以确定结果时,就再继续运算右边的表达式的值; 举例 ...
- css清除浮动主要方法
1.浮动元素尾部添加空div标签,设置css为clear:both: 缺点:如果页面浮动布局多,则需要添加较多div: 2.父级元素定义伪类:after和zoom:1: .father:after{d ...
- vue监听scroll使用报错的解决办法
错误说明:在切换路由以后,依旧在其他页面触发了scroll有关的函数, 错误原因:在spa项目中,window对象是不变的,所以每次使用后需要销毁. 解决办法:vue的生命周期destroyed中销毁 ...
- 快速开发 jQuery 插件的 10 大技巧
在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就可以 copy & paste 大部分的代码结构,只要专注最主要的逻辑代码就行了. ...
- 自动删除文件脚本(Linux shell脚本)
每天在/home/face/capturepic/2017/目录下都会产生很多文件 /home/face/capturepic/2017/4/21 /home/face/capturepic/2017 ...
- Django学习日记07_Admin
django.contrib django.contrib是django中附带的一个工具集,由很多的附加组件组成.这些附加组件包括管理工具(django.contrib.admin).用户鉴别系统(d ...
- java多线程(一)-概述
最近这段在看java多线程编程方面的东西.所以特写了几篇文章,来总结和回顾一下自己所学习到的相关知识.因为水平有限,文章中总结不全面甚至理解错误的地方,欢迎读者指点批评. 我们平时所接触到的程序,都是 ...
- Swift语言中与C/C++和Java不同的语法(四)
这一节,我们将会讨论一下Swift中的函数相关的基本内容 首先是函数的创建: func sayHello (name:String) -> String { return "Hello ...
- unittest单元测试框架详解
unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...