http://codeforces.com/contest/4/problem/D

题目大意:

给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一定大于前一个,求最长的这个序列的长度,并且给出一组可行解。

思路:最长上升子序列

#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<iostream>
int n,f[],from[];
int tot,c[];
struct node{
int h,w,id;
}a[];
int read(){
int t=,f=;char ch=getchar();
while (ch<''||ch>''){if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
bool operator <(node a,node b){
return (a.h<b.h&&a.w<b.w);
}
bool cmp(node a,node b){
if (a.h==b.h) return a.w<b.w;
else return a.h<b.h;
}
int main(){
n=read();n++;
int cnt=;
for (int i=;i<=n;i++){
a[++cnt].h=read();a[cnt].w=read();
a[cnt].id=i-;
if (i!=&&(a[cnt].h<=a[].h||a[cnt].w<=a[].w)) cnt--;
}
n=cnt;
std::sort(a+,a++n,cmp);
int ans=,mx=;
f[]=;
for (int i=;i<=n;i++){
for (int j=;j<i;j++)
if (f[i]<f[j]+&&a[j]<a[i]&&f[j])
from[i]=j,f[i]=f[j]+;
if (f[i]>ans) ans=f[i],mx=i;
}
if (ans==) {printf("");return ;}
int top=;
for (int i=mx;i!=;i=from[i]){
c[++top]=a[i].id;
}
printf("%d\n",ans-);
for (int i=top;i>=;i--)
printf("%d ",c[i]); }

Codeforces 4D Mysterious Present的更多相关文章

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

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

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

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

  3. dp--C - Mysterious Present

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

  4. 【Codeforces 4D】Mysterious Present

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

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

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

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

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

  7. D - Mysterious Present

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

  8. CodeForces 1043D Mysterious Crime 区间合并

    题目传送门 题目大意: 给出m个1-n的全排列,问这m个全排列中有几个公共子串. 思路: 首先单个的数字先计算到答案中,有n个. 然后考虑多个数字,如果有两个数字相邻,那么在m个串中必定都能找到这两个 ...

  9. D. Mysterious Present DAG dp

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

随机推荐

  1. office web apps server 问题和解决办法

    New-OfficeWebAppsFarm –InternalURL "http://owa.zjkhlib.com" –AllowHttp –EditingEnabled 错误1 ...

  2. 移动web app开发框架

    文章地址:http://www.cnblogs.com/soulaz/p/5586787.html jQuery Mobile jQuery Mobile框架能够帮助你快速开发出支持多种移动设备的Mo ...

  3. 日积月累:EditText软键盘的显示和隐藏

    在工作过程中,常常会遇见需要根据自己的需求,控制文本框的键盘显示和隐藏. 通过查阅Android文档,介绍可以通过在清单文件中<activity>元素中添加android:windowSo ...

  4. js中的数据类型及其转换

    Js中的数据类型 Js中的数据类型一共有六种,即number,string,boolean,underfine,null,object. 一,number Number数据类型指的是数字,可以为整型, ...

  5. HBase总结(十二)Java API 与HBase交互实例

    HBase提供了Java Api的訪问接口,掌握这个就跟Java应用使用RDBMS时须要JDBC一样重要 import java.io.IOException; import org.apache.h ...

  6. windows安装PHP5.4.13 +Apache2.4.4(转)

    下载了PHP5.4.13 +Apache2.4.4,开始在网上下教程. 环境配置遇到的第一个问题就是网上很多教程是针对老版本的PHP和apache,不得不搜了很久才搜到这篇文章. windows安装P ...

  7. 一个C++基于boost简单实现的线程池

    xl_blocking_queue.h ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ...

  8. IE下判断IE版本语法使用

    先摆一下判断IE版本语法 <!--[if lte IE 6]> <![endif]--> IE6及其以下版本可见 <!--[if lte IE 7]> <![ ...

  9. (转)Android 判断用户2G/3G/4G移动数据网络

    在做 Android App 的时候,为了给用户省流量,为了不激起用户的愤怒,为了更好的用户体验,是需(要根据用户当前网络情况来做一些调整的,也可以在 App 的设置模块里,让用户自己选择,在 2G ...

  10. LSI SAS 3008配置操作

    配置 LSI SAS 3008 介绍LSISAS3008的配置操作. 4.1 登录CU界面 介绍登录LSISAS3008的CU配置界面的方法. 4.2 创建RAID 介绍在LSISAS3008扣卡上创 ...