当前位置:网站首页>The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
2022-07-27 11:13:00 【T_ Y_ F666】
Longest ascending subsequence model AcWing 1017. Kidd's glider
Original link
Algorithm tags
DP linear DP Longest ascending subsequence
Ideas 
Code
#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] End point Pass from left to right a[j] The longest distance
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] End point Pass from right to left a[j] The longest distance
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);
}
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support 
边栏推荐
- The largest square of leetcode (violence solving and dynamic programming solving)
- Learning notes uni app
- 最长上升子序列模型 AcWing 1010. 拦截导弹
- 349两个数组的交集和01两数之和
- The influence of the number of non-zero values in the picture on Classification
- antd中table hover上去的背景色样式修改
- 涌现与形态的局部差异和整体差异
- Introduction to software vulnerability analysis (I)
- The difference between scalar, vector, matrix and tensor in deep learning
- The article will not keep VIP charges all the time. It will be open for a period of time
猜你喜欢

Cancer DDD

Shortest moving distance and entropy of morphological complex

迭代次数的差异与信息熵

涌现与形态的局部差异和整体差异

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

How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review

Redis+caffeine two-level cache enables smooth access speed

最长上升子序列模型 AcWing 272. 最长公共上升子序列

antd table+checkbox 默认值显示

2022牛客多校 (3)J.Journey
随机推荐
Cancer DDD
计算重叠积分的第二种方法
349两个数组的交集和01两数之和
What changes will metauniverse bring to the music industry in the trillion market?
Opengauss kernel analysis - statistics and row count estimation
10 complete half of the questions
IO流_字符流、IO流小结、IO流案例总结
Use of beautifulsoup
迭代次数的差异与信息熵
How to build a real-time development platform to deeply release the value of enterprise real-time data?
12 is at least twice the maximum number of other numbers
Data assets are king. How to analyze the relationship between enterprise digital transformation and data asset management?
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
Iptables prevent nmap scanning and binlog explanation
熵与形态的非递进现象
A verification test of the relationship between iteration number and entropy
Background color style modification on table hover in antd
Non progressive phenomena of entropy and morphology
How to assemble a registry