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)围成一个圆圈,要求求 ...
随机推荐
- java如何引入接口中定义的常量
接口 (A.java) : package config; public interface A { String PROJECT_ROOT_DIR = System.getProperty(&quo ...
- 转: linux文件链接(软链接和硬链接)
链接:一种在共享文件和访问它的用户的若干目录项之间建立联系的一种方法. Linux中包括两种链接:硬链接(Hard Link)和软链接(Soft Link),软链接又称为符号链接(Symbolic l ...
- bootstrap 导航栏
非常好的一篇文章: http://webdesigntutsplus.s3.amazonaws.com/tuts/312_bs/My-Bootstrap-Site-NAVBAR/navbar-exam ...
- jQuery中on()方法用法实例详解
这篇文章主要介绍了jQuery中on()方法用法,实例分析了on()方法的功能及各种常见的使用技巧,并对比分析了与bind(),live(),delegate()等方法的区别,需要的朋友可以参考下 本 ...
- stringstream字符串流
例题详解 題目:输入的第一行有一个数字 N 代表接下來有 N 行資料,每一行資料里有不固定個數的整數(最多 20 個,每行最大 200 個字元),請你寫一個程式將每行的总和印出來. 輸入: 3 1 2 ...
- setImageResource与setImageBitmap的区别
同样的布局文件,小分辨率手机: 1.使用setImageBitmap设置时,出现如下现象: 2.使用setImageResource时,图片显示正常 原因: setImageResource(id) ...
- xcode 不值钱的动画UIButton
#import "ViewController.h" @interface ViewController () /** 按钮 */ @property(nonatomic,weak ...
- Google Maps 学习笔记(三)
1.GPolyline折线对象和GPolygon多边形对象 html标签中必须包含v="urn:schemas-microsoft--com:vml"的命名空间 <html ...
- webservice主流框架Axis、Axis2、XFire、CXF的比较
http://ws.apache.org/axis/ http://axis.apache.org/axis2/java/core/ http://xfire.codehaus.org/ http:/ ...
- Android应用开发提高篇(2)-----文本朗读TTS(TextToSpeech)
链接地址:http://www.cnblogs.com/lknlfy/archive/2012/02/26/2368696.html 一.概述 TextToSpeech,就是将文本内容转换成语音,在其 ...