当前位置:网站首页>最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
2022-07-27 10:35: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);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Li Hongyi_ Machine learning_ Assignment 4 (detailed explanation)_ HW4 Classify the speakers
- Application of 5g private network in smart medicine
- Yiwen counts NFT projects valued at more than US $100million
- The difference between scalar, vector, matrix and tensor in deep learning
- Symmetric encryption and asymmetric encryption
- Influence of black and white pixel distribution on iteration times
- A verification test of the relationship between iteration number and entropy
- Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
- Thank you for your likes and attention
- Maximized array sum after 13 K negations
猜你喜欢

antd table中排序th阻止悬停变色+table悬停行变色+table表头变色

Deep analysis: what is diffusion model?

ethereum rpc

Antd table+checkbox default value display

FAQs of "relay chain" and "dot" in Poka ecosystem

Li Hongyi_ Machine learning_ Assignment 4 (detailed explanation)_ HW4 Classify the speakers

解决 ImportError: cannot import name 'abs' 导入tensorflow报错

Redis high availability principle

Use of parsel

Derivation of the detailed expansion sto overlap integrals
随机推荐
【FPGA教程案例40】通信案例10——基于FPGA的简易OFDM系统verilog实现
How to build a real-time development platform to deeply release the value of enterprise real-time data?
How to modify the strict mode under MySQL so that adding new users by inserting user table is successful
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
学习笔记-微信支付
349两个数组的交集和01两数之和
Shock simulation of engine mounting system transient modal dynamic analysis and response spectrum analysis
学习笔记-简易服务器实现
Remember not to copy your group work, students. Fortunately, you only passed two questions. Don't have an accident
tensorflow运行报错解决方法
How to create a.Net image with diagnostic tools
Maximized array sum after 13 K negations
antd table+checkbox 默认值显示
Substr and substring function usage in SQL
2022牛客多校训练(3)A-Ancestor 题目翻译
黑白像素分布对迭代次数的影响
Using skills of word
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
C语言 2:求三数字最大值,求三数字中间值,编写程序步骤
推导STO双中心动能积分的详细展开式