当前位置:网站首页>最长上升子序列模型 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);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- All about PDF crack, a complete solution to meet all your PDF needs
- [南京大学]-[软件分析]课程学习笔记(一)-introduction
- Go write a program that runs within a certain period of time
- 联想混合云Lenovo xCloud:4大产品线+IT服务门户
- Novice entry SCM must understand those things
- 使用AGC重签名服务前后渠道号信息异常分析
- Tips for using jeditabletable
- Three series of BOM elements
- 2 - 3 arbre de recherche
- How to realize the high temperature alarm of the machine room in the moving ring monitoring system
猜你喜欢

How to realize the high temperature alarm of the machine room in the moving ring monitoring system

如何在HarmonyOS应用中集成App Linking服务

联想混合云Lenovo xCloud:4大产品线+IT服务门户

idea里使用module项目的一个bug

ncs成都新电面试经验

AVL balanced binary search tree

Data type - integer (C language)

归并排序和非比较排序

2-3 lookup tree

下载和安装orcale database11.2.0.4
随机推荐
Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
关于基于kangle和EP面板使用CDN
使用AGC重签名服务前后渠道号信息异常分析
let const
redis故障处理 “Can‘t save in background: fork: Cannot allocate memory“
[kuangbin] topic 15 digit DP
GOLand idea intellij 无法输入汉字
IP guard helps energy enterprises improve terminal anti disclosure measures to protect the security of confidential information
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
uniapp 微信小程序监测网络
Data type - floating point (C language)
Teach you how to select PCB board by hand (II)
MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)
打通法律服务群众“最后一公里”,方正璞华劳动人事法律自助咨询服务平台频获“点赞”
21 general principles of wiring in circuit board design_ Provided by Chengdu circuit board design
leetcode134. gas station
Interpolation lookup (two methods)
如何在HarmonyOS应用中集成App Linking服务
2-3 lookup tree
Opencv learning note 3 - image smoothing / denoising