当前位置:网站首页>ACM最长不下降子序列问题
ACM最长不下降子序列问题
2022-08-09 11:02:00 【抓个马尾女孩】
给定一串数,求出其最长不下降子序列
本题是经典的一道dp线性问题,定义一个三维数组,a[i][1]表示数值,a【i】【2】表示i到n最长的子序列长度,a【i】【3】表示i子序列后跟的数的位置。
#include<iostream>
using namespace std;
int a[100][10],k,l;
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i=i+1)
{
cin>>a[i][1];
a[i][2]=1;
a[i][3]=0;
}
for(int i=n-1;i>=1;i=i-1)
{
k=0;
l=0;
for(int j=i+1;j<=n;j=j+1)
if((a[j][1]>a[i][1])&&a[j][2]>l)
{
k=j;
l=a[j][2];
}
if(l>0)
{
a[i][2]=l+1;
a[i][3]=k;
}
}
k=1;
for(int i=1;i<=n;i=i+1)
if(a[i][2]>a[k][2])
k=i;
cout<<"max= "<<a[k][2]<<endl;
while(k!=0)
{
cout<<a[k][1]<<' ';
k=a[k][3];
}
return 0;
}
边栏推荐
- PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization论文阅读
- tensorflow实现线性方程的参数调整
- 备战金三银四:如何成功拿到阿里offer(经历+面试题+如何准备)
- ThreadLocal及其内存泄露分析
- FreeRTOS列表和列表项源码分析
- 解决1.tensorflow运行使用CPU不使用GPU 2.tensorflow环境下的GPU版本号 3.tensorflow和cuda以及cudnn版本对应问题 4.查看cuda和cudnn版本
- Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
- PTA习题 阶梯电价(C)
- 图片查看器viewer
- faster-rcnn learn
猜你喜欢
centos7.5 设置Mysql开机自启动
基于STM32F103移植FreeRTOS
b站up主:空狐公子 --矩阵求导(分母布局)课程笔记
MATLAB代码实现三次样条插值
人物 | 从程序员到架构师,我是如何快速成长的?
C语言统计不同单词数
【VIBE: Video Inference for Human Body Pose and Shape Estimation】论文阅读
非科班毕业生,五面阿里:四轮技术面+HR一面已拿offer
Since I use the HiFlow scene connector, I don't have to worry about becoming a "dropper" anymore
性能测试(01)-jmeter元件-线程组、调试取样器
随机推荐
The torch. The stack () official explanation, explanation and example
grpc系列-初探grpc 路由注册和转发实现
Qt获取EXE可执行文件的上一级目录下的文件
Tensorflow realize parameter adjustment of linear equations
centos7.5 设置Mysql开机自启动
OpenSSF的开源软件风险评估工具:Scorecards
PoseNet: A Convolutional Network for Real-Time 6-DOF Camera Relocalization论文阅读
详细的np.matmul / np.dot / np.multiply / tf.matmul / tf.multiply / *
electron 应用开发优秀实践
∘(空心的点乘)的数学含义
Beauty Values
jvm-类加载系统
Looper 原理浅析
Numpy常用操作博客合集
最长回文子串
Preparation for gold three silver four: how to successfully get an Ali offer (experience + interview questions + how to prepare)
matlab图像分割,从基因芯片荧光图像中提取阴性点(弱)和阳性点(强)
golang 三种指针类型具体类型的指针、unsafe.Pointer、uintptr作用
CentOS6.5 32bit安装Oracle、ArcSde、Apache等配置说明
OpenSSF's open source software risk assessment tool: Scorecards