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> ...
随机推荐
- hibernate CasCade deleted object ould be re-saved by cascade
这个问题个人认为看你用的那种方式,如果是注解式的 比如: @ManyToMany(cascade={CascadeType.MERGE,CascadeType.REFRESH,CascadeType. ...
- 关于text-decoration无法清除继承的问题
因为text-decoration的值可以叠加,所以即使设置了none,浏览器也是看成是叠加,而不是清除的意思.
- 152.Maximum Product Subarray---dp---连续子数组的最大乘积---《编程之美》2.13子数组的最大乘积
题目链接:https://leetcode.com/problems/maximum-product-subarray/description/ 题目大意:给出一串数组,找出连续子数组中乘积最大的子数 ...
- Ubuntu或者Ubuntu server重新设置IP地址
1.打开终端输入: sudo vi /etc/network/interfaces 2.进入编辑页面 改一处,添加5行内容,如下图: 3.修改好后esc :wq进行保存 4.输入: sudo / ...
- Codefroces 919D Substring(拓扑排序+DP)
题目链接:http://codeforces.com/problemset/problem/919/D 题目大意:给你一张有向图,给你每个顶点上的字母和一些边,让你找出一条路径,路径上的相同字母数最多 ...
- Valid Parentheses——栈经典
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the inpu ...
- Windows内核执行体对象管理器的操作过程与分析
我之前写过一个有关于对象管理的读书笔记.但是这篇文章与前面的不同,这是我个人对对象管理器到底是什么的一个分析,而且也是直接对WRK代码进行的阅读. 执行体对象即我们通常所言的内核对象,我们知道Wind ...
- MYSQL-----流程控制 if() 函数的用法
语法:IF(condition,result,result) 如果函数的第一个参数中给定的condition符合条件(如,condition不等于0或者不为NULL),那么函数的执行结果为第二个参数中 ...
- 常用 Java Profiling 工具的分析与比较
转自:http://www.ibm.com/developerworks/cn/java/j-lo-profiling/index.html 在 Java 程序的开发过程中,不可避免地会遇到内存使用. ...
- Graves of the Internet - 互联网坟墓
Graves of the Internet - 互联网坟墓 互联网公司逝去产品列表 以此祭奠那些夕阳下的奔跑,祭奠那些逝去的青春 演示地址 点击 这里 https://myvin.github.io ...