hdu1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069
分析: 每种石头有六种方法,那么等效为:有6*n种石头。
根据x和y排序(要保证相应的x、y总有x>=y),然后dp[i]=
max{s[i].z,s[i].z+dp[j]}(j<i,且石块i放于石块j上,符合题意)。
其实就是最长上升子序列的换种求法。。。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#define LL long long
using namespace std;
int dp[];
struct node
{
int x,y,z;
}s[];
int cmp(node a,node b)
{
if(a.x!=b.x)return a.x>b.x;
else if(a.y!=b.y)return a.y>b.y;
else return a.z>b.z;
}
int main()
{
int n,cas=;
while(scanf("%d",&n)&&n)
{
int tot=;
for(int i=;i<=n;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
s[tot].x=x;s[tot].y=y;s[tot].z=z;
tot++;
s[tot].x=x;s[tot].y=z;s[tot].z=y;
tot++;
s[tot].x=y;s[tot].y=x;s[tot].z=z;
tot++;
s[tot].x=y;s[tot].y=z;s[tot].z=x;
tot++;
s[tot].x=z;s[tot].y=y;s[tot].z=x;
tot++;
s[tot].x=z;s[tot].y=x;s[tot].z=y;
tot++;
}
sort(s+,s+tot,cmp);
memset(dp,,sizeof(dp));
dp[]=s[].z;
int ans=-;
for(int i=;i<tot;i++)
{//printf("%d %d %d\n",s[i].x,s[i].y,s[i].z);
int mx=;
for(int j=;j<i;j++)
if(s[j].x>s[i].x&&s[j].y>s[i].y&&dp[j]+s[i].z>mx)mx=dp[j]+s[i].z;
if(mx==)dp[i]=s[i].z;
else
dp[i]=mx;
ans=max(mx,ans);
}
printf("Case %d: maximum height = %d\n",cas++,ans);
}
}
hdu1069(dp)的更多相关文章
- hdu-1069(dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 题意:一群猴子,给出n块砖的长x宽y高z,用这些砖拼起的高度最高是多少, 要求底下的砖的长宽都要 ...
- LightOJ 1033 Generating Palindromes(dp)
LightOJ 1033 Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- lightOJ 1047 Neighbor House (DP)
lightOJ 1047 Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...
- UVA11125 - Arrange Some Marbles(dp)
UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 初探动态规划(DP)
学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...
- Tour(dp)
Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...
- 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)
.navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...
- Leetcode之动态规划(DP)专题-详解983. 最低票价(Minimum Cost For Tickets)
Leetcode之动态规划(DP)专题-983. 最低票价(Minimum Cost For Tickets) 在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行.在接下来的一年里,你要旅行的 ...
随机推荐
- QT调用CURL
QProcess *mProcess; QStringList arguments; arguments<<"--disable-epsv" <<" ...
- OS X 10.10 Yosemite Beta能够下载了
刚刚启动迅雷.蹦出一消息.点击后出现-- watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmlzdGE5OTk5OQ==/font/5a6L5L2T/fon ...
- C# - ref
The ref keyword causes an argument to be passed by reference, not by value. The effect of passing by ...
- ftk学习记(对话框篇)
[声明:版权全部,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 前面谈到了输入法,首先看一看效果. 上面有4个输入框,大家能够分别试试,看看效果怎样. 今天,我 ...
- 从response.header中提取cookie,在request里添加cookie
// List<String> resp = new ArrayList<String>(); // HeaderIterator headers ...
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations
D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...
- HTML——使用表格对表单进行布局
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3Vuc2h1bWlu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA ...
- 菜鸟版JAVA设计模式—从买房子看代理模式
今天学习了代理模式. 相对于适配器模式,或者说装饰器模式,代理模式理解起来更加简单. 代理这个词应该比較好理解,取代去做就是代理. 比方,我们买卖房子,那么我们会找中介,我要卖房子,可是我们没有时间去 ...
- c++在string类源
一:回想 (1)c++中的string类是在面试中和笔试中常常考的题目: project代码免费下载 string类的自行实现 (2)c++中的string类和fstream类合起来是处理外部数据的利 ...
- spring获取bean 实例
ApplicationContext ctx = new ClassPathXmlApplication("applicationContext.xml"); DataSource ...