动态规划-LIS
https://vjudge.net/contest/297216?tdsourcetag=s_pctim_aiomsg#problem/E
#include<bits/stdc++.h>
using namespace std; struct note
{
int x,y,id;
} m[];
int f[];
int c[];
set<int> s;
bool cmp(note a,note b)
{
return a.x<b.x;
}
int main()
{
int cnt=;
int x,y;
while(cin>>x>>y)
{
m[++cnt].x=x;
m[cnt].y=y;
m[cnt].id=cnt;
}
sort(m+,m++cnt,cmp);
for(int i=; i<=cnt; i++)
for(int j=; j<i; j++)
{
if(m[i].y<m[j].y&&m[i].x>m[j].x&&f[i]<f[j]+)
{
f[i]=f[j]+;
c[i]=j;
}
}
int flag=;
int maxx=f[];
for(int i=;i<=cnt;i++)
{
if(f[i]>maxx)
{
maxx=f[i];
flag=i;
}
}
while(flag!=)
{
s.insert(flag);
flag=c[flag];
}
printf("%d\n",s.size());
for(auto i:s)
printf("%d\n",m[i].id); // s.insert(m[flag].id);
// while(c[flag]!=0)
// {
// s.insert(m[c[flag]].id);
// flag=c[flag];
// }
// printf("%d\n",s.size());
// for(auto i:s)
// printf("%d\n",i); }
动态规划-LIS的更多相关文章
- 非 动态规划---LIS
题目:一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度.(见动态规划---LIS) /* 题目:一个序列有N个数:A[1],A[2],…,A[N],求出最长非降子序列的长度 ...
- 2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS)
2021.12.06 P2501 [HAOI2006]数字序列(动态规划+LIS) https://www.luogu.com.cn/problem/P2501 题意: 现在我们有一个长度为 n 的整 ...
- BZOJ_1609_[Usaco2008_Feb]_Eating_Together_麻烦的聚餐_(动态规划,LIS)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1609 给出一串由1,2,3组成的数,求最少需要改动多少个数,使其成为不降或不升序列. 分析 法 ...
- 动态规划-LIS最长上升子序列
优化链接 [https://blog.csdn.net/George__Yu/article/details/75896330] #include<stdio.h> #include< ...
- HDU - 1160 FatMouse's Speed 动态规划LIS,路径还原与nlogn优化
HDU - 1160 给一些老鼠的体重和速度 要求对老鼠进行重排列,并找出一个最长的子序列,体重严格递增,速度严格递减 并输出一种方案 原题等于定义一个偏序关系 $(a,b)<(c.d)$ 当且 ...
- HDU-1051/POJ-1065 Wooden sticks 木棍子(动态规划 LIS 线型动归)
嘤嘤嘤,实习半年多的小蒟蒻的第一篇博客(题解) 英文的: There is a pile of n wooden sticks. The length and weight of each stick ...
- POJ_1631_Bridging_Signals_(动态规划,LIS)
描述 http://poj.org/problem?id=1631 铁路左右相连,要求去掉一些边,使得剩下的边不交叉,求剩余边数的最大值. Bridging signals Time Limit: 1 ...
- POJ_1065_Wooden_Sticks_(动态规划,LIS+鸽笼原理)
描述 http://poj.org/problem?id=1065 木棍有重量 w 和长度 l 两种属性,要使 l 和 w 同时单调不降,否则切割机器就要停一次,问最少停多少次(开始时停一次). Wo ...
- P1091 合唱队形题解(洛谷,动态规划LIS,单调队列)
先上题目 P1091 合唱队形(点击打开题目) 题目解读: 1.由T1<...<Ti和Ti>Ti+1>…>TK可以看出这题涉及最长上升子序列和最长下降子序列 2 ...
随机推荐
- 分享一个VueCli 3.0的项目模板
个人搭建的Vue项目模板 默认自带 Vuex Less 封装内容如下 vue.config axios 封装 vue 配置环境文件 vue 自定义路径映射 (cli3.0取消了默认@ 映射src的 ...
- Loading class `com.mysql.jdbc.Driver'. The new driver class is `com.mysql.cj.jdb 问题
是因为最新的数据库驱动的原因,用较早的版本就可以了. <dependency> <groupId>mysql</groupId> <artifactId> ...
- Ubuntu版本linux系统安装git
可以使用apt-get方式安装,也可以下载源代码安装,我们这里使用apt-git安装.但由于直接使用 sudo apt-get install git 安装的版本较老,因此我们参考[2]中给出的PPA ...
- 简单的C#网络爬虫
Source Code: http://download.csdn.net/download/qdalong/10271880 这是爬取网页内容,像是这对大家来说都是不难得,但是在这里有一些小改动,代 ...
- P2255 [USACO14JAN]记录奥林比克
P2255 [USACO14JAN]记录奥林比克 题目描述 农民约翰热衷于所有寒冷天气的运动(尤其是涉及到牛的运动), 农民约翰想录下尽可能多的电视节目. 为moolympics电视时间表由N个不同的 ...
- Rest分页接口开发
简单描述:需求说后端写一个XX数据的分页接口,给前端口调用,其实有一个PageHelper的工具类可以直接使用但是老大不让用,得用sql写,.小Kiss啦.直接上代码 代码: //Controller ...
- github徽标引入
官网: https://shields.io/ 示例:  request.post() request.head() requst.put() request.patch( ...
- 【GIT】git 删除本地分支和远程分支、本地代码回滚和远程代码库回滚
[git 删除本地分支] git branch -D br [git 删除远程分支] git push origin :br (origin 后面有空格) git代码库回滚: 指的是将代码库某分支退 ...