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 最长上升子序列+倒序打印路径的更多相关文章

  1. 最长公共子序列Lcs(打印路径)

    给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的).   比如两个串为:   abcicba abdkscab   ab是两个串的子序列,abc也是,abca也是,其中abca是这 ...

  2. HDU - 1160 最长上升子序列以及记录路径

    题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...

  3. 51nod_1006 最长公共子序列,输出路径【DP】

    题意: 给出两个字符串A B,求A与B的最长公共子序列(子序列不要求是连续的). 比如两个串为: abcicba abdkscab ab是两个串的子序列,abc也是,abca也是,其中abca是这两个 ...

  4. zoj 3088 Easter Holidays(最长路+最短路+打印路径)

    Scandinavians often make vacation during the Easter holidays in the largest ski resort Are. Are prov ...

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

  6. POJ 2250(LCS最长公共子序列)

    compromise Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u   Descri ...

  7. 动态规划——最长公共子序列LCS及模板

    摘自 https://www.cnblogs.com/hapjin/p/5572483.html 这位大佬写的对理解DP也很有帮助,我就直接摘抄过来了,代码部分来自我做过的题 一,问题描述 给定两个字 ...

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

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

  9. Codeforces 4D Mysterious Present

    http://codeforces.com/contest/4/problem/D 题目大意: 给出n个信封,这n个信封有长和宽,给出卡片的尺寸,求取能够装入卡片的最长的序列,序列满足后一个的长和宽一 ...

随机推荐

  1. 移植linux-2.6.32.2到qq2440

    编译该版本内核使用的编译器版本:arm-linux-gcc 3.4.1 1.获取linux-2.6.32.2 2.解压内核 3.切换到刚解压的内核目录下: cd linux-2.6.32.2 4.修改 ...

  2. 用Python编写的第一个回测程序

    用Python编写的第一个回测程序 2016-08-06 def savfig(figureObj, fn_prefix1='backtest8', fn_prefix2='_1_'): import ...

  3. 关于oracle的准备

    作者:Steven Feuerstein 提高编写PL/SQL代码数量及质量的四个简单易行指导方针 我从1990年就开始编写PL/SQL代码.这意味着我已经编写了几万行的软件代码,但我确信,其中的绝大 ...

  4. 自定义datagridview列,却提示DataGridView 控件中至少有一列没有单元格模板

    哈哈,一个小误区,你看看设计窗体生成的代码,DataGridView的列不是GridViewColumn 而是DataGridViewTextBoxColumn你只要添加这个类型的对象就可以了,我也是 ...

  5. Head First 设计模式 --5 单例模式

    单例模式:确保一个类只有一个实例,并提供一个全局访问点.用到的设计原则:1.封装变化2.组合优于集成3.针对接口变成而不是针对实现4.为交互对象之间的松耦合设计而努力5.类应该对扩展开放,对修改关闭6 ...

  6. UIApplication sharedApplication详细解释-IOS

    iPhone应用程序是由主函数main启动,它负责调用UIApplicationMain函数,该函数的形式如下所示: int UIApplicationMain ( int argc, char *a ...

  7. oracle PROCEDURE AS IS区别

    在存储过程(PROCEDURE)和函数(FUNCTION)中没有区别,在视图(VIEW)中只能用 ,在游标(CURSOR)中只能用IS不能用AS.

  8. “不支持一个STA线程上针对多个句柄的WaitAll。”的解决方案

    一.异常提示 不支持一个 STA 线程上针对多个句柄的 WaitAll. 出错界面如下图: 二.解决方法 先直接上解决方案吧.其实解决方法很简单如下面的代码直接把main函数的[STAThread]属 ...

  9. B:冷血格斗场

    总时间限制: 1000ms 内存限制: 65536kB描述为了迎接08年的奥运会,让大家更加了解各种格斗运动,facer新开了一家冷血格斗场.格斗场实行会员制,但是新来的会员不需要交入会费,而只要同一 ...

  10. 如何查看ipa包支持哪些cpu指令集

    将ipa包下载到本地 cd 到其所在目录 unzip lipo -info Moon(app名)