codeforces mysterious present 最长上升子序列+倒序打印路径
link:http://codeforces.com/problemset/problem/4/D
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
][] = {{-,},{,},{,-},{,},{-,-},{-,},{,-},{,}};
using namespace std;
],path[],End;
bool flag;
typedef struct node
{
int W,H,In;
bool operator < (const node &other) const
{
if(W!=other.W) return W<other.W;
else return H<other.H;
}
}node;
node ma[];
bool judge(node a,node b)
{
if(a.W<b.W&&a.H<b.H) return true; else return false;
}
void print_ans(int i)
{
) return;
print_ans(path[i]);
printf();
}
int main(void)
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin );
#endif // ONLINE_JUDGE
while(~scanf("%d%d%d",&n,&w,&h))
{
flag=;
;i<n;++i)
{
int a,b;
scanf("%d%d",&a,&b);
if(a<=w||b<=h) continue;
flag=true; ma[cnt].W=a; ma[cnt].H=b; ma[cnt].In=i;
cnt++;
}
if(!flag)
{
printf("0\n"); continue;
}
sort(ma,ma+cnt);
ans=;
memset(d,,sizeof(d));
memset(path,-,sizeof(path));
End=;
;i<cnt;++i) d[i]=;
;i<cnt;++i)
{
;
;j<i;++j)
{
if(judge(ma[j],ma[i]))
{
if(tmp<d[j])
{
tmp=d[j]; path[i]=j;
}
}
}
d[i]=tmp+;
if(ans<d[i])
{
ans=d[i]; End=i;
}
}
printf("%d\n",ans);
print_ans(End);
printf("\n");
// printf("%d\n",ma[End-1].In+1);
}
;
}
最长上升子序列还写这么挫哦
这两天沉迷于kpw……囧
codeforces mysterious present 最长上升子序列+倒序打印路径的更多相关文章
- 最长公共子序列Lcs(打印路径)
给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为: abcicba abdkscab ab是两个串的子序列,abc也是,abca也是,其中abca是这 ...
- HDU - 1160 最长上升子序列以及记录路径
题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...
- 51nod_1006 最长公共子序列,输出路径【DP】
题意: 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为: abcicba abdkscab ab是两个串的子序列,abc也是,abca也是,其中abca是这两个 ...
- zoj 3088 Easter Holidays(最长路+最短路+打印路径)
Scandinavians often make vacation during the Easter holidays in the largest ski resort Are. Are prov ...
- Codeforces 3A-Shortest path of the king(BFS打印路径)
A. Shortest path of the king time limit per test 1 second memory limit per test 64 megabytes input s ...
- POJ 2250(LCS最长公共子序列)
compromise Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descri ...
- 动态规划——最长公共子序列LCS及模板
摘自 https://www.cnblogs.com/hapjin/p/5572483.html 这位大佬写的对理解DP也很有帮助,我就直接摘抄过来了,代码部分来自我做过的题 一,问题描述 给定两个字 ...
- Codeforces Beta Round #4 (Div. 2 Only) D. Mysterious Present 记忆化搜索
D. Mysterious Present 题目连接: http://www.codeforces.com/contest/4/problem/D Description Peter decided ...
- Codeforces 4D Mysterious Present
http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...
随机推荐
- 单据类型BE构建
开发流程:BE--UI--发布在开发时有必要对元数据.代理调用.弱类型.强类型有所了解基本的单据开发包括单据类型BE.单据状态BE.单据BE,下面分别罗列出各单据的BE的设计开发: 本章主要讲解单据类 ...
- js之oop <三>属性标签
读取属性标签 获取对象属性标签,用 Object.getOwnPropertyDescriptor方法.getOwnPropertyDescriptor(); 参数:属性所在对象(object),属性 ...
- [css3]CSS3选择器:nth-child和:nth-of-type之间的差异
by zhangxinxu from http://www.zhangxinxu.com本文地址:http://www.zhangxinxu.com/wordpress/?p=1709 一.深呼吸,直 ...
- 【matlab】膨胀
clear all;close all; BW=zeros(9,10); BW(4:6,4:7) =1 imshow(BW) hold on SE=strel('square',3) BW2=imdi ...
- 【bzoj1084】最大子矩阵
题意 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. \(1≤n≤100,1≤m≤2,1≤k≤10\) 分析 由于\(m\)只有两 ...
- 关于H5中自定义属性的设置和获取
自定义数据属性是在HTML5中新加入的一个特性.简单来说,自定义数据属性规范规定任何以data-开头属性名并且赋值.自定义数据属性是为了保存页面或者应用程序的私有自定义数据,这些自定义数据属性保存进D ...
- python的类和对象——番外篇(类的静态字段)
什么是静态字段 在开始之前,先上图,解释一下什么是类的静态字段(我有的时候会叫它类的静态变量,总之说的都是它.后面大多数情况可能会简称为类变量.): 我们看上面的例子,这里的money就是静态字段,首 ...
- 6/8/9/10/11 Sprint2 看板和燃尽图
端午放假,大家都回家了 页面模块的大体设计,因所找的资料不全,还待改善
- Google Analytics与百度统计原理
Google Analytics与百度统计的统计数据都是有差异的,而且差异非常大,其根本原因在于数据统计的原理和机制是不同的.下面分享一下两位博友李鑫和赵高欣对Google Analytics与百度统 ...
- Js获取后台集合List的值和下标的方法
Js获取后台集合List的值和下标的方法 转载自:http://blog.csdn.net/XiaoKanZheShiJie/article/details/47280449 首先用的是struts2 ...