UVa 407
此问题与求上升序列最大和类似,可以作为DAG模型计算。将每一快砖分解为3块,将所有砖块按照底排序,注意sort排序中涉及到底的两个参数x,y,这时候一定要有优先排,比如先排x再排y,不能同时排x和y,下面排序写法是错误的:
bool operator<(Rec a){
return x<a.x&&y<a.y;
}
/*----UVa437
--首先将每一个长方体按照三个方向,分解为3个长方体
--用dp[i]表示以第i个长方体为底所得到的最大高度
--问题其实和hdu1087一样
*/
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<vector>
#include<string.h>
#include<algorithm>
using namespace std;
const int MAXN = 100;
struct Rec{
int x, y,h;
Rec(int a=0,int b=0,int c=0) :x(a), y(b), h(c){}
bool operator<( Rec a){
//一定要有优先比较顺序,先按照x再按照y
if (x == a.x)
return y < a.y;
return x < a.x;
}
};
Rec rec[MAXN];
int dp[MAXN];
int n;
/*vector<int>vec[MAXN];
int dfs(int i){
int &ans = dp[i];
if (ans >= 0)
return ans;
ans = rec[i].h;
for (int j = 0; j < (int)vec[i].size(); j++)
ans = max(ans, dfs(vec[i][j]) + rec[i].h);
return ans;
}*/
int main(){
int i,j,iCase=1;
int a[3];
while (scanf("%d", &n) && n){
int cnt =1;
for (i = 0; i < n; i++){
scanf("%d%d%d", &a[0], &a[1], &a[2]);
sort(a, a + 3);
rec[cnt++] = Rec(a[0],a[1],a[2]);
rec[cnt++] = Rec(a[1],a[2],a[0]);
rec[cnt++] = Rec(a[0],a[2],a[1]);
}
n = cnt;
sort(rec, rec + n);
int ans = 0;
for (i = 1; i < n; i++){
dp[i] = rec[i].h;
for (j = 1; j < i; j++){
if (rec[j].x < rec[i].x&&rec[j].y < rec[i].y)
dp[i] = max(dp[i], dp[j] + rec[i].h);
}
ans = max(ans, dp[i]);
}
/*for (i = 0; i < n; i++){
vec[i].clear();
for (j = 0; j < n; j++){
if (rec[j] < rec[i])
vec[i].push_back(j);
}
}
int ans = 0;
memset(dp, -1, sizeof(dp));
for (i = 1; i <n; i++){
dp[i] = dfs(i);
ans = max(ans, dp[i]);
}*/
printf("Case %d: maximum height = %d\n",iCase++,ans);
}
return 0;
}
UVa 407的更多相关文章
- 【转】UVa Problem 100 The 3n+1 problem (3n+1 问题)——(离线计算)
// The 3n+1 problem (3n+1 问题) // PC/UVa IDs: 110101/100, Popularity: A, Success rate: low Level: 1 / ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- Fast Matrix Operations(UVA)11992
UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...
- uva 1354 Mobile Computing ——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABGcAAANuCAYAAAC7f2QuAAAgAElEQVR4nOy9XUhjWbo3vu72RRgkF5
- UVA 10564 Paths through the Hourglass[DP 打印]
UVA - 10564 Paths through the Hourglass 题意: 要求从第一层走到最下面一层,只能往左下或右下走 问有多少条路径之和刚好等于S? 如果有的话,输出字典序最小的路径 ...
- UVA 11404 Palindromic Subsequence[DP LCS 打印]
UVA - 11404 Palindromic Subsequence 题意:一个字符串,删去0个或多个字符,输出字典序最小且最长的回文字符串 不要求路径区间DP都可以做 然而要字典序最小 倒过来求L ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- UVA计数方法练习[3]
UVA - 11538 Chess Queen 题意:n*m放置两个互相攻击的后的方案数 分开讨论行 列 两条对角线 一个求和式 可以化简后计算 // // main.cpp // uva11538 ...
- UVA数学入门训练Round1[6]
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include &l ...
随机推荐
- [CF999E]Reachability from the Capital
题目大意:有一个$n$个点$m$条边的有向图,起点$S$,要求你添加最少的边使得$S$可以到达所有点 题解:缩点,答案就是没有入边的强连通分量个数,注意,如果起点$S$所在的强连通块没有入边则不计入答 ...
- [bzoj3813] 奇数国 [线段树+欧拉函数]
题面 传送门 思路 这题目是真的难读......阅读理解题啊...... 但是理解了以后就发现,题目等价于: 给你一个区间,支持单点修改,以及查询一段区间的乘积的欧拉函数值,这个答案对19961993 ...
- [poj] 1149 PIGS || 最大流经典题目
原题 题目大意 给你m个猪圈以及每个猪圈里原来有多少头猪,先后给你n个人,每个人能打开一些猪圈并且他们最多想买Ki头猪,在每一个人买完后能将打开的猪圈中的猪顺意分配在这次打开猪圈里,在下一个人来之前 ...
- BZOJ4894 天赋 【矩阵树定理】
题目链接 BZOJ4894 题解 双倍经验P5297 题解 #include<iostream> #include<cstring> #include<cstdio> ...
- server reached pm.max_children setting (5), consider raising it
先查看日志 /data1/server/php-cgi/var/log/php-fpm.log[19-Dec-2012 11:41:13] WARNING: [pool www] server rea ...
- Windows Server 创建环回网卡
1.以管理员身份运行cmd后,在cmd命令窗口中执行:hdwwiz 启动硬件添加向导. 2.在添加硬件向导中选择手动安装或自动搜索都可以.然后选择网络适配器. 3.选择网络适配器:厂商选择Micros ...
- 洛谷P3112 [USACO14DEC]后卫马克Guard Mark
题目描述 Farmer John and his herd are playing frisbee. Bessie throws the frisbee down the field, but it' ...
- 51nod1086 背包问题 V2——二进制优化
有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1,W2......Wn(Wi为整数),与之相对应的价值为P1,P2......Pn(Pi ...
- Leap Motion颠覆操控体验的超精致手势追踪技术【转】
转自:http://www.cnblogs.com/emouse/archive/2013/02/28/2936689.html 先来看两段简介视频: 看了介绍视频后,对如此次超高精度的手势追踪非常好 ...
- 理解python的super
def super(cls, inst): mro = inst.__class__.mro() return mro[mro.index(cls) + 1] super做了这些事 摘自:https: ...