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. Feather包实现数据框快速读写,你值得拥有

    什么是Feather? Feature是一种文件格式,支持R语言和Python的交互式存储,速度更快.目前支持R语言的data.frame和Python pandas 的DataFrame. Feat ...

  2. kvm命令参数记录

    /usr/libexec/qemu-kvm -cpu host -m 1024 -enable-kvm -drive file=/var/lib/libvirt/images/zxc_linux1.i ...

  3. WPF之换肤

    WPF之换肤 设计原理 WPF换肤的设计原理,利用资源字典为每种皮肤资源添加不同的样式,在后台切换皮肤资源文件. 截图 上图中,第一张图采用规则样式,第二张图采用不规则样式,截图的时候略有瑕疵. 资源 ...

  4. 调用HTMLTestRunner生产的报告内容为空解决办法

    开始代码如下,生成报告内容为空: #coding=utf-8 import unittest,time,reimport requestsimport jsonimport HTMLTestRunne ...

  5. linux系统查找具体进程

    ps -ef | grep '查找内容' eg:ps -ef | grep '测试USB设备穿透'

  6. 用于启动 Windows Phone 8 内置应用的 URI 方案

    本主题列出了可用于启动内置应用的 URI 方案.许多内置于 Windows Phone 的应用,都可以通过调用 LaunchUriAsync(Uri) 和传入一个使用与要启动应用相关的方案的 URI, ...

  7. SVM资料

    解释SMO算法比较好的文档 http://wenku.baidu.com/view/aeba21be960590c69ec3769e.html 参考博客: http://myjuno.blogbus. ...

  8. day01作业

    Java技术按照用途不同分为三大版本,分别是JavaSE.JavaEE和JavaMeJava虚拟机就是一个虚拟的用于执行字节码文件的计算机.它是Java最核心的技术,是Java跨平台的基础.DOS命令 ...

  9. GPS 与 北斗 初步对比

    一.脉冲 GPS每秒可获得一次卫星星历电文,秒脉冲的误差服从正态分布,锁住的可用卫星达到四颗以上时,授时脉冲的1精度在100 ns以内:当锁住的可用卫星少于四颗时,解算方程组的信息不够充分,授时精度将 ...

  10. oracle 一个网站

    http://www.oracle.com/technetwork/cn/articles/11g-pivot-101924-zhs.html