集训第五周 动态规划 B题LIS
Description
Input
Output
Sample Input
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
Sample Output
Case 3: maximum height = 28
Case 4: maximum height = 342
#include"iostream"
#include"algorithm"
#include"cstring"
#include"cstdio"
#define inf -1e9
using namespace std;
int n,ans,f,ff; struct node{
int x,y,z;
void getdata(int a,int b,int c)
{
x=a;y=b;z=c;
}
bool operator < (const node &a1) const
{
if(x!=a1.x) return x>a1.x;
return y>a1.y;
}
}a[]; int dp[]; void Init()
{
f=;int aa,bb,cc;
a[].x=a[].y=;
for(int i=;i<n;i++)
{
cin>>aa>>bb>>cc;
a[f++].getdata(aa,bb,cc);
a[f++].getdata(aa,cc,bb);
a[f++].getdata(cc,aa,bb);
a[f++].getdata(cc,bb,aa);
a[f++].getdata(bb,aa,cc);
a[f++].getdata(bb,cc,aa);
}
sort(a,a+f);
} bool isok(node a1,node a2)
{
if(a2.x>a1.x&&a2.y>a1.y) return true;
return false;
} void Work()
{
int MAX=inf;
memset(dp,,sizeof(int)*f);
for(int i=;i<f;i++)
{
for(int j=;j<=i;j++)
if(isok(a[i],a[j])&&dp[j]+a[i].z>dp[i])
dp[i]=dp[j]+a[i].z;
MAX=max(dp[i],MAX);
}
ans=MAX;
} void Print()
{
cout<<"Case "<<ff++<<": maximum height = "<<ans<<endl;
} int main()
{
ff=;
while(cin>>n&&n)
{
Init();
Work();
Print();
}
return ;
}
O(O_O)O
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=+;
struct node
{
int l,w,h;
void init(int a,int b,int c)
{
l=a;
w=b;
h=c;
}
}f[maxn];
int dp[maxn],e,ca=; bool cmp(node x1,node x2)
{
return x1.l*x1.w>x2.l*x2.w;
} void Work()
{
sort(f,f+e,cmp);
int maxx=-1e9;
for(int k=;k<e;k++)
{
memset(dp,,sizeof(dp));
dp[k]=f[k].h;
for(int i=;i<e;i++)
{
if(i==k) continue;
for(int j=;j<i;j++)
{
if(f[j].l>f[i].l&&f[j].w>f[i].w) dp[i]=max(dp[j]+f[i].h,dp[i]);
}
maxx=max(dp[i],maxx);
}
}
cout<<"Case "<<ca++<<": maximum height = "<<maxx<<endl;
} int main()
{
int n;
while(cin>>n&&n)
{
e=;
int a,b,c;
for(int i=;i<=n;i++)
{
cin>>a>>b>>c;
f[e++].init(a,b,c);
f[e++].init(a,c,b);
f[e++].init(b,a,c);
f[e++].init(b,c,a);
f[e++].init(c,a,b);
f[e++].init(c,b,a);
}
Work();
}
return ;
}
集训第五周 动态规划 B题LIS的更多相关文章
- 集训第五周动态规划 E题 LIS
Description The world financial crisis is quite a subject. Some people are more relaxed while others ...
- 集训第五周动态规划 D题 LCS
Description In a few months the European Currency Union will become a reality. However, to join the ...
- 集训第五周动态规划 C题 编辑距离
Description Let x and y be two strings over some finite alphabet A. We would like to transform x int ...
- 集训第五周动态规划 I题 记忆化搜索
Description Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激.可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你.Michael想知道 ...
- 集训第五周动态规划 H题 回文串统计
Hrdv is interested in a string,especially the palindrome string.So he wants some palindrome string.A ...
- 集训第五周动态规划 G题 回文串
Description A palindrome is a symmetrical string, that is, a string read identically from left to ri ...
- 集训第五周动态规划 F题 最大子矩阵和
Given a two-dimensional array of positive and negative integers, a sub-rectangle is any contiguous s ...
- 集训第五周 动态规划 K题 背包
K - 背包 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- 集训第五周动态规划 J题 括号匹配
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
随机推荐
- 【底层原理】高级开发必须懂的"字节对齐"
认识字节对齐之前,假定int(4Byte),char(1Byte),short(2Byte) 认识字节对齐 先看段代码: struct Data1 { char a; int b; short c; ...
- 01背包(分组) HDOJ 4341 Gold miner
题目传送门 题意:有n个金矿,每个金矿有抓取的消耗的时间和价值,矿工在原点,问在T时间内能得到的最大的价值 分析:唯一和01背包不同的是金矿可能共线,也就是抓取近的金矿后才能抓后面共线的金矿.这是分组 ...
- 题解报告:hdu 2086 A1 = ?
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2086 Problem Description 有如下方程:Ai = (Ai-1 + Ai+1)/2 - ...
- 1、IO概述及File类
- 1272 最大距离 只想到了dp
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1272 离散化后,用dp[i]表示向右,大于等于i这个数字的最大位置 dp ...
- 转】R利剑NoSQL系列文章 之 Hive
原博文出自于: http://blog.fens.me/category/%E6%95%B0%E6%8D%AE%E5%BA%93/page/3/ 感谢! Posted: Jul 27, 2013 Ta ...
- Laravel环境搭建
在有了初步认知后,当然就要开始在自己的电脑上搭建Laravel的开发环境了. 系统环境需求 PHP 5.3.7或者更高版本,如果没有系统没有安装PHP环境的,请到下面地址下载:http://cn2.p ...
- Android开发中使用数据库时出现java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
最近在开发一个 App 的时候用到了数据库,可是在使用数据库的时候就出现了一些问题,在我查询表中的一些信息时出现了一下问题: Caused by: java.lang.IllegalStateExce ...
- 微信小程序组件解读和分析:十五、switch 开关选择器
switch 开关选择器组件说明: switch,开关选择器.只能选择或者不选.这种属于表单控件或者查询条件控件. switch 开关选择器示例代码运行效果如下: 下面是WXML代码: [XML] 纯 ...
- git --版本对比
比较暂存区域和工作目录 -git diff 分别拷贝暂存区和工作目录的文件到a和b文件夹 --- //表示旧文件 暂存区的 +++ //表示新文件 工作目录的 F 一页一页往下移 B 一 ...