题目大意

给你一张宽为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. js: get event handler bound to the element

    jQuery._data(jQuery(this)[0], "events" ).click[0].handler $._data( $("#myabc")[0 ...

  2. Ubuntu中PyCharm中字体设置

    在Ubuntu安装的PyCharm与Windows不同,除了Editor中的字体.配色需要设置外,文件操作栏(File--Edit--View--Navigate--Code--Refactor--- ...

  3. Java 开发者不容错过的 12 种高效工具

    Java 开发者常常都会想办法如何更快地编写 Java 代码,让编程变得更加轻松.目前,市面上涌现出越来越多的高效编程工具.所以,以下总结了一系列工具列表,其中包含了大多数开发人员已经使用.正在使用或 ...

  4. [jobdu]扑克牌顺子

    一开始看到题还以为要DFS还是BFS,后来发现完全不用.排个序,然后看看大小王能不能弥补缺口就行,但后来又发现还要排除有相同大小牌的情况. #include <iostream> #inc ...

  5. js中replace用法

    js中replace的用法 replace方法的语法是:stringObj.replace(rgExp, replaceText) 其中stringObj是字符串(string),reExp可以是正则 ...

  6. MySQL主从复制中断处理一例

    收到mysql主从中断报警邮件,马上登上服务器查看,发现是中继日志损坏. Show slave status\G,提示中继日志损坏,按以往的做法,根据提示重新指定合适的日志文件以及pos点.  Rel ...

  7. ActionBar官方教程(10)ActionBar的下拉列表模式

    Adding Drop-down Navigation As another mode of navigation (or filtering) for your activity, the acti ...

  8. Android 完全退出程序,以及再按一次返回键退出程序

    再按一次返回键退出最终完整方案: boolean isExit; @Override    protected void onCreate(Bundle savedInstanceState) {   ...

  9. Oracle系列之视图

    涉及到表的处理请参看原表结构与数据  Oracle建表插数据等等 创建视图,把tb_Employee表sal<1000的雇员,映射到该视图( view) create or replace vi ...

  10. tarjan 算法讲解(转)

     转自:https://www.byvoid.com/blog/scc-tarjan/ 網誌 列表 標籤 項目 關於 聯繫 四月142009 作者:byvoid 閱讀: 158882 計算機科學 圖論 ...