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)围成一个圆圈,要求求 ...
随机推荐
- 【转】CentOS图形界面的开启与关闭
源自:http://blog.sina.com.cn/s/blog_4a1f76860100zpus.html 安装CentOS 5.6系统的时候我没有先装任何组件,现在用X Window,需要再安装 ...
- SQL Server 排名函数实现
在SQL Server 中有四大排名函数分别是: 1.row_number() 2.ntile() 3.rank() 4.dense_rank() -------------------------- ...
- Google浏览器调试js
1.进入source找到js位置 一般js文件就到js目录下找,tpl中的就到tpl中找. 我这次写在tpl中的,就到list中找,它就把list中的js单独显示出来了. 2.设置断点,进行排错.刷新 ...
- Java中static、this、super、final的用法
一. static 请先看下面这段程序: public class Hello{public static void main(String[] args){//(1)System. ...
- Tomcat 的context.xml
1. 在tomcat 5.5之前: --------------------------------------------------------------- Context体如今/conf/se ...
- Android 类似未读短信图标显示数字效果的分析
之前一直以为是应用本身在对图标进行修改,看了源码之后发现其实主要的工作并不是应用自己完成的,主要的工作在是launcher里面完成的. 关于系统里面类似未读短信的具体处理流程如下, 原理 一个应用要实 ...
- zoj 2256 Mincost
#include<stdio.h> int main(void) { int kil; ; double sum; ) { sum=; flag=; while(kil) { ) { su ...
- If We Were a Child Again
Description The Problem The first project for the poor student was to make a calculator that can jus ...
- Depth-First Search
深度搜索和宽度搜索对立,宽度搜索是横向搜索(队列实现),而深度搜索是纵向搜索(递归实现): 看下面这个例子: 现在需要驾车穿越一片沙漠,总的行驶路程为L.小胖的吉普装满油能行驶X距离,同时其后备箱最多 ...
- 在C#调用C++的DLL方法(二)生成托管的DLL
写操作之前,还是扼要的说一下托管与非托管C++的区别好了,其实我也并没有深入了解过托管C++的特点所在,其最大的特征就是可以由系统来调试回收相关的代码资源,跟C#的特性一样,只是编程风格跟C++类似而 ...