题目大意

给你一张宽为w,长为h的的贺卡,然后给你n个信封,每个信封宽为wi,长为hi,问你最多能在贺卡上嵌套多少个信封,如果某个信封i如果能够装在信封j里,当且仅当w[i]<w[j]&&h[i]<h[j]

题解

就是LIS嘛,没啥好说的。。。

代码

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define MAXN 5006
int pre[MAXN],dp[MAXN];
pair<pair<int,int>,int> a[MAXN];
void dfs(int x)
{
if(pre[x]!=-1) dfs(pre[x]);
printf("%d ",a[x].second+1);
}
int main()
{
int n,w,h;
scanf("%d%d%d",&n,&w,&h);
memset(pre,-1,sizeof(pre));
for(int i=0;i<n;i++)
{
scanf("%d%d",&a[i].first.first,&a[i].first.second);
a[i].second=i;
}
sort(a,a+n);
for(int i=0;i<n;i++)
{
if(w>=a[i].first.first||h>=a[i].first.second) continue;
dp[i]=1;
for(int j=0;j<i;j++)
if(a[i].first.first>a[j].first.first&&a[i].first.second>a[j].first.second&&dp[j]+1>dp[i])
{
dp[i]=dp[j]+1;
pre[i]=j;
}
}
int ans=max_element(dp,dp+n)-dp;
printf("%d\n",dp[ans]);
if(dp[ans])
{
dfs(ans);
printf("\n");
}
return 0;
}

Codeforces4D - Mysterious Present(LIS)的更多相关文章

  1. D. Mysterious Present (看到的一个神奇的DP,也可以说是dfs)

    D. Mysterious Present time limit per test 2 seconds memory limit per test 64 megabytes input standar ...

  2. Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索

    D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D Description Peter decided ...

  3. dp--C - Mysterious Present

    C - Mysterious Present Peter decided to wish happy birthday to his friend from Australia and send hi ...

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

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

  5. D - Mysterious Present

    这个题和求最长递增序列的题类似,为了能输出一组可行的数据,我还用了一点儿链表的知识. Description Peter decided to wish happy birthday to his f ...

  6. codeforces mysterious present 最长上升子序列+倒序打印路径

    link:http://codeforces.com/problemset/problem/4/D #include <iostream> #include <cstdio> ...

  7. Codeforces 4D Mysterious Present

    http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...

  8. 【Codeforces 4D】Mysterious Present

    [链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性 ...

  9. D. Mysterious Present DAG dp

    https://codeforces.com/problemset/problem/4/D 这个题目比较简单,就是一个DAG模型,这个可以看看紫书学习一下, 我这次是用dp来写的,用记忆化搜索也许更好 ...

随机推荐

  1. linux管道的容量和内部组织方式

    1.管道容量  count=65536,即64KB #include<stdio.h> #include<sys/types.h> #include<unistd.h&g ...

  2. uCGUI窗口操作要点

    uCGUI窗口操作要点 1. 创建一个窗口的时候,会给此窗口发送“创建(WM_CREATE)”消息,从而执行它的回调函数:如果创建窗口的标志带有“可视标志(WM_CF_SHOW)”,那么在后续执行GU ...

  3. Python之添加新元素

    现在,班里有3名同学: >>> L = ['Adam', 'Lisa', 'Bart'] 今天,班里转来一名新同学 Paul,如何把新同学添加到现有的 list 中呢? 第一个办法是 ...

  4. 微软Hololens学院教程-Hologram 210 Gaze(凝视)【微软教程已经更新,本文是老版本】

    这是老版本的教程,为了不耽误大家的时间,请直接看原文,本文仅供参考哦!原文链接:https://developer.microsoft.com/EN-US/WINDOWS/HOLOGRAPHIC/ho ...

  5. Python的字符串操作和Unicode

    字符串类型 str:Unicode字符串.采用''或者r''构造的字符串均为str,单引号可以用双引号或者三引号来代替.无论用哪种方式进行制定,在Python内部存储时没有区别. bytes:二进制字 ...

  6. 背景CSS

    .op_weather4_twoicon_day:hover .op_weather4_twoicon_hover { background-image: -webkit-linear-gradien ...

  7. MongoDB实战指南(七):MongoDB复制集之复制集工作机制

    http://www.cnblogs.com/longshiyVip/p/5097336.html 概述了复制集,整体上对复制集有了个概念,但是复制集最重要的功能之——自动故障转移是怎么实现的呢?数据 ...

  8. js设置radio选中

    在页面数据绑定时,经常会遇到给radio设置选中,以下是我写的js方法,经测试可以使用.欢迎拍砖 <html> <head> <script type="tex ...

  9. java.lang.Boolean为null时

    public class TestBooleanNull { public static void main(String[] args) { if (test()) { System.out.pri ...

  10. 自编的CHtmlView浏览器,怎么截获超连接,不让新窗口在IE中打开

    blog <自编的CHtmlView浏览器,怎么截获超连接,不让新窗口在IE中打开>    http://bbs.csdn.net/topics/10299197    http://so ...