D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)
2 seconds
64 megabytes
standard input
standard output
Peter decided to wish happy birthday to his friend from Australia and send him a card. To make his present more mysterious, he decided to make a chain. Chain here is such a sequence of envelopes A = {a1, a2, ..., an}, where the width and the height of the i-th envelope is strictly higher than the width and the height of the (i - 1)-th envelope respectively. Chain size is the number of envelopes in the chain.
Peter wants to make the chain of the maximum size from the envelopes he has, the chain should be such, that he'll be able to put a card into it. The card fits into the chain if its width and height is lower than the width and the height of the smallest envelope in the chain respectively. It's forbidden to turn the card and the envelopes.
Peter has very many envelopes and very little time, this hard task is entrusted to you.
The first line contains integers n, w, h (1 ≤ n ≤ 5000, 1 ≤ w, h ≤ 106) — amount of envelopes Peter has, the card width and height respectively. Then there follow n lines, each of them contains two integer numbers wi and hi — width and height of the i-th envelope (1 ≤ wi, hi ≤ 106).
In the first line print the maximum chain size. In the second line print the numbers of the envelopes (separated by space), forming the required chain, starting with the number of the smallest envelope. Remember, please, that the card should fit into the smallest envelope. If the chain of maximum size is not unique, print any of the answers.
If the card does not fit into any of the envelopes, print number 0 in the single line.
2 1 1
2 2
2 2
1
1
3 3 3
5 4
12 11
9 8
3
1 3 2
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct abcd
{
int x,y,z,t;
} abcd;
abcd a[];
int n;
int dfs(int x)
{
if(a[x].z!=-)return a[x].z;
a[x].z=;
for(int i=; i<=n; i++)
{
if(a[x].x<a[i].x&&a[x].y<a[i].y)
{
if(dfs(i)+>a[x].z)
a[x].z=dfs(i)+,a[x].t=i;
}
}
return a[x].z;
}
int main()
{
int i,j,m=;
cin>>n;
for(i=; i<=n; i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].t=-,a[i].z=-;
}
dfs();
cout<<a[].z<<endl;
i=;
while(a[i].t!=-)
{
if(i!=)
cout<<" ";
cout<<a[i].t;
i=a[i].t;
}
cout<<endl;
}
D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)的更多相关文章
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D Description Peter decided ...
- dp--C - Mysterious Present
C - Mysterious Present Peter decided to wish happy birthday to his friend from Australia and send hi ...
- modifytime是一个神奇的column name----这边文章是错的totally,因为我的实验不彻底。timestamp属性很神奇,头一个timestamp,会自动的成DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
在mysql里边modifytime是一个神奇的column name,试一下. 请执行sql语句 CREATE TABLE `test_time` ( `modifytime` timestamp ...
- 一个神奇的???whatever~~
一个神奇的类,用来封装消息数据,统一数据传递接口,从unity引擎源码拷贝而来. #include <iostream> #include <assert.h> #includ ...
- 记一个神奇的WAS问题:sibuswsgw-sibuswsgw_console.jar invalid LOC header (bad signature) 分类: WebSphere 2015-08-06 23:21 9人阅读 评论(0) 收藏
今天晚上,出现了一个神奇的WAS问题,详细问题异常信息如下: [15-8-6 22:13:29:146 CST] 00000013 ApplicationMg A WSVR0203I: 应用程序:is ...
- 微信图片上传,遇到一个神奇的jgp
微信图片上传,获取图片base64遇到一个神奇的 jgp var imgFn = function (event) { event.preventDefault(); var id = '#'+$ ...
- JS高级---一个神奇的原型链
一个神奇的原型链 <script> var divObj=document.getElementById("dv"); console.dir(divObj); //d ...
- Bugku-CTF之这是一个神奇的登陆框
Day32 这是一个神奇的登陆框 http://123.206.87.240:9001/sql/ flag格式flag{}
- WWW 2015:一个神奇的会议
2015:一个神奇的会议" title="WWW 2015:一个神奇的会议"> 作者:微软亚洲研究院研究员 袁进辉 WWW 2015(24th Internatio ...
随机推荐
- MySQL下载安装、基本配置、问题处理
一 mysql介绍 MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下公司.MySQL 最流行的关系型数据库管理系统,在 WEB 应用方面MySQL是 ...
- 利用WHID为隔离主机建立隐秘通道
0 引言 从2014年BADUSB出现以后,USB-HID攻击就这一直被关注,且具争议.争议的焦点是USB-HID的实战效果过于“鸡肋”,无论从早期的BADUSB,还是到后来的各种USB-HID设备, ...
- 解决在linux环境下面不显示验证码的问题
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt235 解决在linux环境下面不显示验证码的问题1.tomcat ...
- 锤子坚果pro突破京东10万好评,还有什么是锤子科技做不出...
作为2017年手机圈明星产品的锤子科技坚果Pro,可是一点都不安分呢! 9月份锤子科技推出一款新机型--坚果Pro银魂定制版 这在动漫圈跟手机圈都掀起一股不小的浪潮. 外观漂亮,颜值超高,续航时间长. ...
- Jquery 清空input file的值
var file = $(obj).parent().find(".fileData"); $(file).val('');
- lua代码的加载
lua代码的加载 Openresty是什么 OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,通过把lua嵌入到Nginx中,使得我们可以用轻巧的lua语言进行nginx的 ...
- 转:【Java集合源码剖析】LinkedHashmap源码剖析
转载请注明出处:http://blog.csdn.net/ns_code/article/details/37867985 前言:有网友建议分析下LinkedHashMap的源码,于是花了一晚上时 ...
- 团队作业4——第一次项目冲刺(Alpha版本)2017.4.22
昨天来不及编写,这是4月22日的日志,现在补上. 1.开完站立式会议后的合照 2.任务分解图 3.开会讨论的结果,任务分派 队员 今日进展 明日安排 陈鑫龙 原型设计图分析,设计登陆界面原稿 实现登陆 ...
- 201521123068《Java程序设计》第5周学习总结
1. 本周学习总结 1.1 尝试使用思维导图总结有关多态与接口的知识点. 查看脑图->多态与接口 1.2 可选:使用常规方法总结其他上课内容. 2. 书面作业 1.代码阅读:Child压缩包内源 ...
- 201521123015 《Java程序设计》第3周学习总结
本周学习总结 初学面向对象,会学习到很多碎片化的概念与知识.尝试学会使用思维导图将这些碎片化的概念.知识组织起来.请使用纸笔或者下面的工具画出本周学习到的知识点. 书面作业 Q1.代码阅读 publi ...