集训第五周 动态规划 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 ...
随机推荐
- oracle数据库当前用户下所有表名和表名的注释
select a.TABLE_NAME,b.COMMENTSfrom user_tables a,user_tab_comments bWHERE a.TABLE_NAME=b.TABLE_NAMEo ...
- Code:Blocks 中文乱码问题原因分析和解决方法
下面说说修改的地方. 1.修改源文件保存编码在:settings->Editor->gernal settings 看到右边的Encoding group Box了吗?如下图所示: Use ...
- 数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight
题目传送门 /* 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 */ #include <cstdio> #include <a ...
- 暴力 hihoCoder 1178 计数
题目传送门 /* 暴力:这题真是醉了,直接暴力竟然就可以了!复杂度不会分析,不敢写暴力程序.. 枚举x,在不重复的情况下+ans,超过范围直接break */ #include <cstdio& ...
- asp.net core连接sqlserver
开发环境:win7,vs2017,sqlserver2014 vs上建立一个asp.net core web项目和一个.net core的类库项目DBA 简单起见,在DBA项目中就一个类SqlServ ...
- D. Mahmoud and a Dictionary 种类并查集
http://codeforces.com/contest/766/problem/D 所谓种类并查集,题型一般如下:给定一些基本信息给你,然后又给出一些信息,要求你判断是真是假.例如给出a和b支持不 ...
- 聊5块钱P2V
上一秒还在写代码,下一秒就跑机房干活. 这台机器产制石器时代,重启一次后再就启动不了了.这个故障处理的方式我们以后再谈. 今天聊聊啥是P2V,国人总喜欢弄些稀奇古怪的定义来证明自己技术很牛X,就跟当年 ...
- 掌握Spark机器学习库-07-回归分析概述
1)回归与分类算法的区别 回归的预测结果是连续的,分类的预测结果是离散的. 2)spark实现的回归算法有: 3)通过相关系数衡量线性关系的程度
- 【C++】模板简述(三):类模板
上文简述了C++模板中的函数模板的格式.实例.形参.重载.特化及参数推演,本文主要介绍类模板. 一.类模板格式 类模板也是C++中模板的一种,其格式如下: template<class 形参名1 ...
- jboss中JVM监控
1)打开 http://server-name-or-ip/jmx-console/HtmlAdaptor2)在 jboss.system 节点找到 type=ServerInfo ,点击进入3)找到 ...