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. SOFTWARE_INTRODUCE_01

    &amp;amp;amp;amp;lt;br data-mce-bogus="1"&amp;amp;amp;amp;gt;&amp;amp;amp;amp; ...

  2. [深入React] 3.JSX的神秘面纱

    <div> <List /> </div> 会被编译为: React.createElement("div",null, React.creat ...

  3. 深入解读ESB与SOA的关系

    时至今日,SOA的概念渐渐清晰了.   有关ESB的概念,已经吵了好多年了,还是没有定论. 我个人认为,ESB本来就是抽象的概念,而且内涵丰富,在不同的场合含义不同.因此应该从不同的角度来认识.   ...

  4. 程序猿的道路~~(How to be a programmer?)

    程序猿的道路其实很简单,主要就是三条: Learn (学习), Practice(练习), Summary(总结) 推荐给新手程序猿两篇文章: 给程序员新手的一些建议 程序员技术练级攻略 当然了,整个 ...

  5. (3)选择元素——(16)延伸阅读(Further reading)

    The topic of selectors and traversal methods will be explored in more detail in Chapter 9. A complet ...

  6. Android 推断当前Activity是不是最后一个Activity 以及 应用或Activity是否存在

    推断当前Activity是最后一个Activity: 在Activity的方法中, 有一个方法isTaskRoot()方法, 这种方法能够推断当前Activity是否是最后一个Activity, 假 ...

  7. Mysql数据库的mysql Schema 究竟有哪些东西&amp; 手工注入的基础要领

    #查看数据库版本号 mysql> select @@version; +------------+ | @@version  | +------------+ | 5.5.16-log | +- ...

  8. 解决Android单个dex文件不能超过65536个方法问题

    当我们的项目代码过大时,编译运行时会报Unable to execute dex: method ID not in[0, 0xffff]: 65536)错误.当出现这个错误时说明你本身自己的工程代码 ...

  9. 50个android开发技巧

    50个android开发技巧 http://blog.csdn.net/column/details/androidhacks.html

  10. UITextField点击return后注销第一响应者

    // 当点击了return按钮,就让text调用自己的endEditing方法 [textField addTarget:textField action:@selector(endEditing:) ...