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 ...
随机推荐
- 框架整合——Spring与MyBatis框架整合
Spring整合MyBatis 1. 整合 Spring [整合目标:在spring的配置文件中配置SqlSessionFactory以及让mybatis用上spring的声明式事务] 1). 加入 ...
- Kafka中操作topic时 Error:Failed to parse the broker info from zookeeper
Kafka中操作topic时 Error: Failed to parse the broker info from zookeeper 1.问题描述 2.问题原因 kafka在启动后 ...
- Spring bean中的properties元素内的name 和 ref都代表什么意思啊?
<bean id="userAction" class="com.neusoft.gmsbs.gms.user.action.UserAction" sc ...
- Windows noinstall zip 安装MySQL。
听完数据库老师的课,想在Windows下通过命令行的方法安装MySQL5.7,于是开了这个坑,终于把这个坑填上了. 第一步:下载MySQL 的noinstall zip ,点击该链接下载,或者复制链接 ...
- Spark 贝叶斯分类算法
一.贝叶斯定理数学基础 我们都知道条件概率的数学公式形式为 即B发生的条件下A发生的概率等于A和B同时发生的概率除以B发生的概率. 根据此公式变换,得到贝叶斯公式: 即贝叶斯定律是关于随机事件A和B ...
- 《深入浅出MySQL》之SQL基础
SQL是Structure Query language(结构化查询语言)的缩写,它是使用关系模型的数据库应用语言.在众多开源数据中,MySQL正式其中最杰出的代表,MySQL是由三个瑞典人于20世纪 ...
- C# 文件的上传和下载
本文主要介绍一下,在APS.NET中文件的简单上传于下载,上传是将文件上传到服务器的指定目录下,下载是从存入数据库中的路径,从服务器上下载. 1.上传文件 (1)页面代码 <table alig ...
- 201521123040《Java程序设计》第7周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 参考资料: XMind 2. 书面作业 1.ArrayList代码分析 1.1 解释ArrayList的contains源代 ...
- 201521123088《Java程序设计》第七周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 ArrayList代码分析1.1 解释ArrayList的contains源代码源代码: //contain ...
- 201521123068《Java程序设计》第6周学习总结
1. 本周学习总结 1.1 面向对象学习暂告一段落,请使用思维导图,以封装.继承.多态为核心概念画一张思维导图,对面向对象思想进行一个总结. 点击->面向对象学习 2. 书面作业 1.clone ...