ZOJ1076
来源:互联网 发布:淘宝试用报告哪里看 编辑:程序博客网 时间:2024/06/11 03:01
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76
先以起点为关键字从小到大排序,再求最长上升子序列(这里的上升是指右边的起点大于左边的终点)。
#include<iostream>#include<memory.h>#include<algorithm>using namespace std;struct node{ int l,r; int number;};node data[1100];int father[1100];int ans,pos;void Find(int x, int deep){ if (father[x] != x) Find(father[x],deep+1); if (deep != 1) cout<<data[x].number<<' '; else cout<<data[x].number<<endl;}int LIS(int n, node a[]){ int b[1100]; int MAX = 0; pos = 0; for (int i=0; i<n; i++) { b[i] = 0; for (int j=0; j<i; j++) if (a[i].l > a[j].r && b[j] > b[i]) { b[i] = b[j]; father[i] = j; } b[i]++; if (b[i] > MAX) { MAX = b[i]; pos = i; } } return MAX;}int cmp(node a, node b){ return (a.l < b.l || (a.l == b.l && a.r < b.r));}int main(){ int n; while (cin>>n && n) { for (int i=0; i<n; i++) { data[i].l = data[i].r = data[i].number = 0; father[i] = i; } for (int i=0; i<n; i++) { cin>>data[i].l>>data[i].r; data[i].number = i+1; } sort(data,data+n,cmp); int ans = LIS(n,data); Find(pos,1); } return 0;}
0 0
- zoj1076
- zoj1076
- zoj1076
- zoj1076
- ZOJ1076
- [水]ZOJ1076
- zoj1076-Gene Assembly
- zoj1076 Gene Assembly
- zoj1076 gene assembly
- ZOJ1076(贪心算法)
- ZOJ1076-Gene Assembly(贪心)
- zoj1076 Gene Assembly 活动安排 dp
- zoj1076----------------Gene Assembly 动态规划,最大上升序列
- qt-qml移动开发之在ios上开发和部署app流程简介
- Homebrew简介及安装
- iOS编程基础之基本控件
- 视频基本知识
- 文件IO(文件指针)
- ZOJ1076
- 《匠人精神》读书笔记要点记录及自我剖析
- static关键字
- 数论_1
- 尝试向分析类转型2--工具使用
- 快速掌握Lua 5.3 —— 字符串库 (3)
- xml之CDATA
- STM32中GPIO的8种工作模式详解
- dfs