ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/B
题目:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio>
#include<iostream>
#include<climits> //用INT_MAX
using namespace std;
const int M=; int box[M][];
int height[M];
int number; //互换长宽高,转换砖块的三种类型
void change(int index,int a,int b,int c)
{
box[index][]=a;
box[index][]=b;
box[index][]=c;
} int dp(int j)
{
int& ans=height[j];
if(ans!=-) //搜索过的直接返回
return ans;
for(int i=;i<=number;i++)//搜索每一层
{
if(i!=j)
{
if((box[i][]<box[j][]&&box[i][]<box[j][])||(box[i][]<box[j][]&&box[i][]<box[j][]))
{
int temp=dp(i)+box[i][];
if(temp>ans)
ans=temp;
}
}
}
if(ans==-)//最后一层未更新
ans=;
return ans;
} int main()
{
int n;
int m=;
while(scanf("%d",&n)&&n)
{
int a,b,c;
number=;
box[][]=box[][]=box[][]=INT_MAX;//地板看成无穷大砖块
for(int i=;i<=n;i++)
{
scanf("%d%d%d",&a,&b,&c);
change(++number,a,b,c);
change(++number,b,c,a);
change(++number,c,a,b);
}
for(int i=;i<=number;i++)
{
height[i]=-;
}
printf("Case %d: maximum height = %d\n",m++,dp());
}
return ;
}
每次都想完全自己写,可是自己写的都有很多错误,最后有看了别人的博客。
ZOJ 1093 Monkey and Banana (LIS)解题报告的更多相关文章
- HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)
HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...
- 随手练——ZOJ 1093 Monkey and Banana(动态规划)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=93 一堆科学家研究猩猩的智商,给他M种长方体,每种N个. 然后,将一个 ...
- 「SDOI2014」Lis 解题报告
「SDOI2014」Lis 题目描述 给定序列 \(A\),序列中的每一项 \(A_i\) 有删除代价 \(B_i\) 和附加属性 \(C_i\). 请删除若干项,使得 \(A\) 的最长上升子序列长 ...
- ZOJ Monthly, January 2018 训练部分解题报告
A是水题,此处略去题解 B - PreSuffix ZOJ - 3995 (fail树+LCA) 给定多个字符串,每次询问查询两个字符串的一个后缀,该后缀必须是所有字符串中某个字符串的前缀,问该后缀最 ...
- zoj 2315 New Year Bonus Grant 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1315 题目意思:Bill Hates 是公司的老总,她管辖着很多程序 ...
- hdu1069 Monkey and Banana LIS
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #inc ...
- HDU 1069 Monkey and Banana(二维偏序LIS的应用)
---恢复内容开始--- Monkey and Banana Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K ...
- HDU 1069 Monkey and Banana(转换成LIS,做法很值得学习)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1069 Monkey and Banana Time Limit: 2000/1000 MS (Java ...
- zoj 2313 Chinese Girls' Amusement 解题报告
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1313 题目意思:有 N 个人(编号依次为1~N)围成一个圆圈,要求求 ...
随机推荐
- iOS 开源库
youtube下载神器:https://github.com/rg3/youtube-dl我擦咧 vim插件:https://github.com/Valloric/YouCompleteMevim插 ...
- 15-C语言结构体
目录: 一.大型软件开发 二.头文件和static 三.结构体 四.联合 五.枚举 回到顶部 一.大型软件开发 将一个代码中的内容,拆分成多个文件,最后的可执行文件只要一个. 操作步骤: 1 原来只有 ...
- 第八届河南省赛F.Distribution(水题)
10411: F.Distribution Time Limit: 1 Sec Memory Limit: 128 MB Submit: 11 Solved: 8 [Submit][Status] ...
- Android animation学习笔记之view/drawable animation
前一章中总结了android animation中property animation的知识和用法,这一章总结View animation和Drawable animation的有关知识: View ...
- contextServlet
一:读取配置文件中的参数信息 1.新建servlet文件ContextServlet1,代码为: import java.io.IOException; import java.util.Enumer ...
- Python 3 学习笔记2
教程链接:http://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000 高级特性 切片 取一个l ...
- 浅谈Servlet(一)
一.Servlet技术引言 1.什么是servlet a.Servlet(Server Applet),全称Java Servlet,未有中文译文.是用Java编写的服务器端程序.其主要功能在于交互式 ...
- 设计一个有getMin功能的栈
[说明]: 本文是左程云老师所著的<程序员面试代码指南>第一章中“设计一个有getMin功能的栈”这一题目的C++复现. 本文只包含问题描述.C++代码的实现以及简单的思路,不包含解析说明 ...
- Struts学习之自定义结果集
转自:http://blog.csdn.net/hanxuemin12345/article/details/38763057 项目中我们经常遇到这样的需求——页面部分刷新,例如:添加用户,转到添加用 ...
- servlet三种实现方式之三通过继承HttpServlet开发servlet
servlet有三种实现方式: 1.实现servlet接口 2.继承GenericServlet 3.通过继承HttpServlet开发servlet 第三种: import java.io.*; i ...