当前位置:网站首页>最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
2022-07-07 06:11:00 【T_Y_F666】
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
原题链接
算法标签
DP 线性DP 最长上升子序列
思路
代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 105, INF = 0x3f3f3f3f;
int f[N], a[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=read();
while(t--){
int n=read();
rep(i, 1, n+1){
a[i]=read();
}
int ans=0;
// a[i]为终点 从左到右经过a[j]的最长距离
rep(i, 1, n+1){
f[i]=1;
rep(j, 1, i){
if(a[j]<a[i]){
f[i]=max(f[i], f[j]+1);
}
}
ans=max(ans, f[i]);
}
// a[i]为终点 从右到左经过a[j]的最长距离
Rep(i, n, 0){
f[i]=1;
Rep(j, n, i+1){
if(a[j]<a[i]){
f[i]=max(f[i], f[j]+1);
}
}
ans=max(ans, f[i]);
}
printf("%lld\n", ans);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 如何在图片的目标中添加目标的mask
- Greenplum6.x搭建_环境配置
- 2-3查找樹
- Redis summary
- [step on the pit] Nacos registration has been connected to localhost:8848, no available server
- Splunk query CSV lookup table data dynamic query
- Shell script for changing the current folder and the file date under the folder
- 关于基于kangle和EP面板使用CDN
- 2-3查找树
- Data type - integer (C language)
猜你喜欢
leetcode135. Distribute candy
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
Train your dataset with swinunet
A method for quickly viewing pod logs under frequent tests (grep awk xargs kuberctl)
Low success rate of unit test report
Opencv learning notes II - basic image operations
国标GB28181协议视频平台EasyGBS新增拉流超时配置
Input and output of floating point data (C language)
如何在HarmonyOS应用中集成App Linking服务
联想混合云Lenovo xCloud:4大产品线+IT服务门户
随机推荐
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
【踩坑】nacos注册一直连接localhost:8848,no available server
Three series of BOM elements
The field value in Splunk subquery fuzzy matching CSV is*
ES6_ Arrow function
Greenplum6.x监控软件搭建
POJ - 3784 running medium
数据分析方法论与前人经验总结2【笔记干货】
Qt Charts使用(重写QChartView,实现一些自定义功能)
A bug using module project in idea
Merge sort and non comparison sort
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
关于基于kangle和EP面板使用CDN
let const
What are the advantages of commas in conditional statements- What is the advantage of commas in a conditional statement?
Greenplum6.x搭建_安装
Exercise arrangement 2.10, 11
Gson converts the entity class to JSON times declare multiple JSON fields named
下载和安装orcale database11.2.0.4
[南京大学]-[软件分析]课程学习笔记(一)-introduction