做题链接: D. Mysterious Present
题目:

给出一个限制(w, h),和n个物品的二维信息(wi,hi)求物品二维都满足wi > w, hi > h的前提下的最长二维严格上升子序列以及长度(wi > wi - 1, hi > hi - 1)
如果找不到任何物品就直接输出0.
物品的顺序可以任意,不做要求
1≤n≤5000, 1≤w,h≤1,000,000

解决:

n只有5000,显然本题是具有二维限制的求最长上升子序问题,并输出子序
先按照(x,y)为第一、第二关键字升序排序,然后做一遍最长上升子序,并且注意记录状态转移的路径。

代码:

#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
struct Node{int x, y;int id;
};
bool cmp(Node a, Node b)
{if (a.x == b.x) return a.y < b.y;return a.x < b.x;
}
int n, xx, yy;
vector<Node> q;
struct {int val, pre;
}dp[N];int main()
{cin >> n >> xx >> yy;for (int i = 1; i <= n; i ++ ){int x, y; scanf("%d%d", &x, &y);if (x <= xx || y <= yy) continue;q.push_back({x, y, i});}q.push_back({xx, yy, -1});sort(q.begin(), q.end(), cmp);int mx = -1, id = -1;for (int i = 1; i < q.size(); i ++ )for (int j = 0; j < i && q[j].x < q[i].x; j ++ )if (q[j].y < q[i].y){if (dp[i].val < dp[j].val + 1){dp[i].val = dp[j].val + 1;dp[i].pre = j;if (mx < dp[i].val){mx = dp[i].val;id = i;}}}if (q.size() == 1){cout << 0 << endl;return 0;}// cout << mx << " " << id << endl;// cout << id << " " << q[id].id  <<endl;vector<int> ans;while (id != -1 && id != 0){ans.push_back(q[id].id);// printf("now.id = %d, pre.id = %d\n", q[id].id, q[dp[id].pre].id);id = dp[id].pre;}cout << ans.size() << endl;reverse(ans.begin(), ans.end());for (int x : ans) cout << x << " ";cout << endl;return 0;
}

CF4D D. Mysterious Present相关推荐

  1. [CF4D]Mysterious Present

    4D:Mysterious Present 题意简述 给出一个限制 >(w,h) >(w,h)和 n n个物品的二维信息(xi,yi)(x_i,y_i). 求物品二维都满足限制的前提下,最 ...

  2. 2022.02.05 Mysterious Present神秘的礼物

    https://acs.jxnu.edu.cn/problem/CF4D 描述: Peter decided to wish happy birthday to his friend from Aus ...

  3. Codeforces Beta Round #4 (Div. 2)【完结】

    2022.3.3 题单地址:https://codeforces.com/contest/4 目录 A. Watermelon[思维] B. Before an Exam[贪心] C. Registr ...

  4. 杭电OJ分类题目(4)-Graph

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(4) HDU Graph Theory - U ...

  5. ACM比赛经验、刷题记录及模板库总结(更新中)

    前言 本文所提及的部分题目代码,可以在我的Github上找到 第一部分 经验分享及感受 第二部分 刷题记录 一.基础算法&程序语言 //strlen()函数的复杂度是O(n)要小心 //截取字 ...

  6. Codeforces 4D Mysterious (DP)

     Peter decided to wish happy birthday to his friend from Australia and send him a card. To make hi ...

  7. CentOS Linux解决 Device eth0 does not seem to be present

    通过OVF部署Linux主机后提示 ringing up interface eth0:  Device eth0 does not seem to be present,delaying initi ...

  8. 【ASP.NET Core】解决“The required antiforgery cookie xxx is not present”的错误

    当你在页面上用 form post 内容时,可能会遇到以下异常: The required antiforgery cookie "????????" is not present ...

  9. UserWarning: Label not :NUMBER: is present in all training examples

    UserWarning: Label not :NUMBER: is present in all training examples 目录 UserWarning: Label not :NUMBE ...

最新文章

  1. python简单计算器异常处理_Python实现的简单计算器
  2. 自动飞行控制系统_波音737MAX,安全评估竟是自己做的!飞行员仅用iPad学习驾驶!...
  3. Response对象学习
  4. 域用户组成员 导出_隐私安全,黑客利用Mimikatz提取Windows用户凭证
  5. 【温故知新】CSS学习笔记(背景)
  6. oracle数据泵还原命令,Oracle Linux环境中使用数据泵的形式还原Oracle数据库
  7. CodeForces - 160E Buses and People(线段树+三维偏序)
  8. python爬虫从入门到精通
  9. 【机器学习】 - 各种人脸数据集下载地址及说明汇总
  10. HEVC/H265 性能分析
  11. TortoiseSVN的bin目录下面没有svn.exe
  12. 详解Modbus通信协议---清晰易懂
  13. 被踢出sci_这本世界上创刊最早的期刊竟被踢出 SCI 了?!
  14. 打卡1 谭浩强c语言程序设计第三章
  15. 有哪些比较好的免费简历网站?
  16. ASP.net开发环境配置说明手册
  17. 史上最详细的梯度下降优化算法介绍(从SGD到Adam至Lookahead)
  18. Ubuntu 如何查看显卡型号
  19. 美丽心灵 A Beautiful Mind
  20. 转 vo、po、dto、bo、pojo、entity、mode如何区分

热门文章

  1. springboot毕设项目课堂考勤管理系统设计与实现o2j18(java+VUE+Mybatis+Maven+Mysql)
  2. mysql- 数据库的6种日志:错误日志、通用日志、慢日志、二进制日志、redo log、undo log
  3. 读书笔记二《产品经理从入门到精通》
  4. 世界首台模拟计算机由哪个科学家发明,世界上第一台计算机的发明者是谁?
  5. 【论文笔记】Birthday, Name and Bifacial-security Understanding Passwords of Chinese Web Users
  6. 【前端王一】 - 前端学习路线
  7. Magento key
  8. 商业银行、信托、券商等金融机构与融资租赁的合作模式解析
  9. 《走出软件作坊2》 阿朱出品
  10. 关于Scroller ,scrollTo,scrollBy