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 ...
随机推荐
- POI实现excel各种验证和导入的思路总结
制定标准 导入总是与导出相辅相成的,无规矩不成方圆.所谓的标准都是大家一同来维护和遵守的,那么首先就是制定一个模板. 这样可以减少验证的工作量. 例如时间的规范[yyyy-MM-dd],获取单元格 ...
- TCP/IP协议栈模型
OSI七层模型介绍: 下面4层(物理层.数据链路层.网络层和传输层)主要提供数据传输和交换功能,即以节点到节点之间的通信为主:第4层作为上下两部分的桥梁,是整个网络体系结构中最关键的部分:而上3层(会 ...
- 一、Nginx安装手册
1 nginx安装环境 nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境. gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有g ...
- Struts2中Action接收参数的方法
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt112 Struts2中Action接收参数的方法主要有以下三种: 1.使用A ...
- c# 读取excel数据的两种方法(转)
转载自:http://developer.51cto.com/art/201302/380622.htm, 方法一:OleDb: 用这种方法读取Excel速度还是非常的快的,但这种方式读取数据的时候不 ...
- 新CCIE笔记-IP网络基础
南京捷式泰CCIE重修笔记:更完善更系统的全新笔记 新增内容: 总结.关联知识点.行业小建议 各种认证证书: RHCE VCP OCP MCSEPMP ITIL CCA CCIE CCNP CCNA ...
- 转:【Java集合源码剖析】ArrayList源码剖析
转载请注明出处:http://blog.csdn.net/ns_code/article/details/35568011 本篇博文参加了CSDN博文大赛,如果您觉得这篇博文不错,希望您能帮我投一 ...
- 个人作业(3)----个人总结(Alpha阶段)
一.个人总结. 个人完成的任务:在此阶段我完成了用户调研.部分测试以及部分博客书写. 个人及团队心得:经过几周Alpha阶段开发后,我大致了解了开发软件的过程,开发一个软件并没有以往想象中那么简易,在 ...
- 团队作业8——第二次项目冲刺(Beta阶段)Day1--5.18
1.展开站立式会议: 会议内容:①团队里的新成员做简单的自我介绍. ②讨论每天的任务分配问题. ③提出一个严格要求:博客一定要及时发布,并及时提交作业,遇到困难可以提出来一起解决. ④就现阶段的项目进 ...
- 201521123006 《java程序设计》 第8周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 class ArrayAlg { public static < ...