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个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...
随机推荐
- PHP操作MySQL的常用函数
某些情况下(如html中),调用php的变量时,要给变量加{},若要使字符串变量加上引号,则还需要在{}外加引号 如: $sql="select * from admin where use ...
- 【OOAD】OOAD概述
什么是面向对象? OOP:面向对象编程(Object Oriented Programming,OOP,面向对象程序设计)是一种计算机编程架构.OOP 的一条基本原则是计算机程序是由单个能够起到子程序 ...
- Deep Learning 5_深度学习UFLDL教程:PCA and Whitening_Exercise(斯坦福大学深度学习教程)
前言 本文是基于Exercise:PCA and Whitening的练习. 理论知识见:UFLDL教程. 实验内容:从10张512*512自然图像中随机选取10000个12*12的图像块(patch ...
- javascript数组常用方法汇总
1.join()方法: Array.join()方法将数组中所以元素都转化为字符串链接在一起,返回最后生成的字符串.也可以指定可选的字符串在生成的字符串中来分隔数组的各个元素.如果不指定分隔符,默认使 ...
- CSS Hack大全-教你如何区分出IE6-IE10、FireFox、Chrome、Opera
CSS Hack大全-教你如何区分出IE6-IE10.FireFox.Chrome.Opera 转载自:http://www.jb51.net/article/50116.htm 现在的浏览器IE6- ...
- 最短路径——Floyd算法
如何求一张图中任意两顶点之间的最短路径长度,这里写一种最简单的算法——Floyd算法: #include<stdio.h> #define inf 9999 int main() { ][ ...
- update 多表
update energylog set value=(a.value+c.value)/2from energylog as a, energylog as cwhere a.idvariable= ...
- uva 1658(最小费用最大流)
题意:一个带权有向图,求起点到终点的两条路径权值之和最小,且两条路径没有公共点(除起点,终点): 分析:拆点法,将u拆成u和u',u-u'容量为1,费用为0,这样就能保证每个点只用一次,起点s-s'容 ...
- 解决ajax中文乱码问题
主要遇到的问题: 一.ajax向服务器提交的数据有中文,没有设置编码方式.造成服务器接收到乱码 二.服务器向ajax返回数据中有中文,没有设置响应编码方式,造成ajax接收到乱码 乱码产生的原因:不管 ...
- 自定义控件之 RadioList
var RadioListObj = function (id, url) { this.URL = url;//radiobox source URL this.ID = id;//radioLis ...