D. Mysterious Present

题目连接:

http://www.codeforces.com/contest/4/problem/D

Description

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.

Input

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).

Output

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.

Sample Input

2 1 1

2 2

2 2

Sample Output

1

1

Hint

题意

你有一张长宽为x,y的卡片

你有n个盒子,长宽分别为xi,yi。

然后问你卡片最多塞多少层盒子。

并且把这些盒子按照从里到外输出。

题解:

很显然就是一个dp嘛

由于数据范围只有5000

那就直接n^2暴力去做就好了……

数据范围100000其实也可以做的,写个线段树就好了。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 5005;
int x[maxn],y[maxn],dp[maxn];
int from[maxn],n;
int dfs(int a)
{
if(dp[a])return dp[a];
for(int i=1;i<=n;i++)
{
if(x[a]<x[i]&&y[a]<y[i])
if(dfs(i)+1>dp[a])
{
from[a]=i;
dp[a]=dfs(i)+1;
}
}
return dp[a];
}
int main()
{
scanf("%d",&n);
for(int i=0;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
int ans = dfs(0);
printf("%d\n",ans);
for(int i=from[0];i;i=from[i])
printf("%d ",i);
return 0;
}

Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索的更多相关文章

  1. Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present(LIS)

    传送门 题意: 现在我们有 n 个信封,然后我们有一张卡片,并且我们知道这张卡片的长和宽. 现给出这 n 个信封的长和宽,我们想形成一个链,这条链的长度就是这条链中所含有的信封的数量: 但是需要满足① ...

  2. Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)

    D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...

  3. Codeforces Round #331 (Div. 2) D. Wilbur and Trees 记忆化搜索

    D. Wilbur and Trees Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  4. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  5. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  6. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  7. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  8. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  9. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

随机推荐

  1. Hive ORC表的使用

    创建普通临时表: create table if not exists test_orc_tmp(   name string,   gender string,   cnt BIGINT )row ...

  2. 使用SPLUNK进行简单Threat Hunting

    通过订阅网上公开的恶意ip库(威胁情报),与SIEM平台中网络流量日志进行匹配,获得安全事件告警. 比如,这里有一个malware urls数据下载的网站,每天更新一次: https://urlhau ...

  3. 【Tomcat】 windows下注册tomcat服务以及设置jvm参数

    注册服务: 1 >cd /d D:\Java\tomcat-7.0.57-Css\bin //进入目录 1 >service.bat install  //注册服务,同理删除服务为 rem ...

  4. 某线下赛AWD

    拿别人比赛的来玩一下,或许这就是菜的力量吧. 0x01 任意文件读取: switch ($row['media_type']) { case 0: // 图片广告 ...... break; case ...

  5. SQLite3 使用教学

    source: SQL中文站:http://www.sqlite.com.cn/MySqlite/4/378.Html OS X自从10.4后把SQLite这套相当出名的数据库软件,放进了作业系统工具 ...

  6. 防范SQL注入

    使用占位符的方式写查询语句hibernate

  7. HDU 5348 MZL's endless loop(DFS去奇数度点+欧拉回路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5348 题目大意:给你一张图,有n个点,和m条无向边,让你把m条无向边变成有向边,使得每个节点的|出度- ...

  8. C语言获取输入,按单词输出

    #include <stdio.h> #include <stdlib.h> int main(int argc,char *argv[]) { int num; printf ...

  9. qt调用仪器驱动库dll实现程控

    在<使用qt+visa实现程控>中实现了qt调用visa库的简单Demo本文将尝试使用qt调用仪器驱动库来实现对仪器仪表的程控 开发环境 系统: windows 10 环境: qt 5.8 ...

  10. day2 字符串常用方法总结

    字符串在Python中是常用的功能,我们知道,字符串在Python中存储的形式是以字符数组的形式存在,比如"alex"在内存中的存储形式是:["a"," ...