Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
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 记忆化搜索的更多相关文章
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present(LIS)
传送门 题意: 现在我们有 n 个信封,然后我们有一张卡片,并且我们知道这张卡片的长和宽. 现给出这 n 个信封的长和宽,我们想形成一个链,这条链的长度就是这条链中所含有的信封的数量: 但是需要满足① ...
- Codeforces Round #459 (Div. 2):D. MADMAX(记忆化搜索+博弈论)
D. MADMAX time limit per test1 second memory limit per test256 megabytes Problem Description As we a ...
- 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 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】
Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...
- Codeforces Beta Round #79 (Div. 2 Only)
Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...
- Codeforces Beta Round #77 (Div. 2 Only)
Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...
- Codeforces Beta Round #76 (Div. 2 Only)
Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...
- Codeforces Beta Round #75 (Div. 2 Only)
Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...
随机推荐
- [转载]Android中Bitmap和Drawable
一.相关概念 1.Drawable就是一个可画的对象,其可能是一张位图(BitmapDrawable),也可能是一个图形(ShapeDrawable),还有可能是一个图层(LayerDrawable) ...
- linux的主题与图标
我先在使用arch跟xfce, 速度没得说,偶尔用一下openbox 有一天将xfce的声音给搞没了,完全不知道哪里配置错了,只好将用户文件夹下的所有配置删除,然后重启进入一切又ok啦 说一下主题,小 ...
- Git远程操作详解【转】
转自:http://www.ruanyifeng.com/blog/2014/06/git_remote.html 作者: 阮一峰 日期: 2014年6月12日 Git是目前最流行的版本管理系统,学会 ...
- elasticsearch集群介绍及优化【转】
elasticsearch用于构建高可用和可扩展的系统.扩展的方式可以是购买更好的服务器(纵向扩展)或者购买更多的服务器(横向扩展),Elasticsearch能从更强大的硬件中获得更好的性能,但是纵 ...
- 利用Google API生成二维码
什么是二维码:二维码是二维条形码的一种,可以将网址.文字.照片等信息通过相应的编码算法编译成为一个方块形条码图案,手机用户可以通过摄像头和解码软件将相关信息重新解码并查看内容.读取方式:利用30万画素 ...
- Gradient-Based Learning Applied to Document Recognition 部分阅读
卷积网络 卷积网络用三种结构来确保移位.尺度和旋转不变:局部感知野.权值共享和时间或空间降采样.典型的leNet-5如下图所示: C1中每个特征图的每个单元和输入的25个点相连,这个5* ...
- 使用OpenSSL自签发服务器https证书
OpenSSL官方推荐win32可执行文件版下载:http://www.slproweb.com/products/Win32OpenSSL.html ca.key CA私钥: openssl gen ...
- C语言小程序之整除
看到有人要求用C语言写这样一个小程序,就拿来温习一下 需求:输出从1到2015这2015个自然数中,能被4或5整除,但不能被30整除的数,并计算有多少个数. #include<stdio.h ...
- day2、购物商城
作业:购物商城 商品展示,价格 买,加入购物车 付款,钱不够 代码如下: import codecs #登录接口,用户名密码都正确登录成功,否则失败 def login(your_name,your_ ...
- Q:WCHAR转化为CHAR
A: int len =WideCharToMultiByte(CP_ACP,0,此处是WCHAR的参数,-1,NULL,0,NULL,NULL); WideCharToMultiByte(CP_AC ...