当前位置:网站首页>The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
The longest ascending subsequence model acwing 1017 Strange thief Kidd's glider
2022-07-07 08:51: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 
边栏推荐
- Introduction to data fragmentation
- Implement custom memory allocator
- Three series of BOM elements
- Pointer advanced, string function
- Routing information protocol rip
- What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
- Basic data types and string types are converted to each other
- Greenplum 6.x reinitialization
- Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
- [Yugong series] February 2022 U3D full stack class 005 unity engine view
猜你喜欢

NCS Chengdu New Electric interview Experience

LeetCode 736. Lisp 语法解析

ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒

为什么要选择云原生数据库
![Other 7 features of TCP [sliding window mechanism ▲]](/img/ff/c3f52a7b89804acfd0c4f3b78bc4a0.jpg)
Other 7 features of TCP [sliding window mechanism ▲]
![[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University](/img/e2/519a5267cd5425a83434d2da65ebe6.jpg)
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University

Image segmentation in opencv

【MySQL】数据库进阶之触发器内容详解

Mountaineering team (DFS)

Data type - floating point (C language)
随机推荐
Selenium automation integration, eight years of testing experience, soft test engineer, an article to teach you
How to integrate app linking services in harmonyos applications
opencv 将16位图像数据转为8位、8转16
实现自定义内存分配器
Mock.js用法详解
cmake命令行使用
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
Mountaineering team (DFS)
Rapid integration of authentication services - harmonyos platform
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
Quick sorting (detailed illustration of single way, double way, three way)
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Leetcode 1984. Minimum difference in student scores
登山小分队(dfs)
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
年薪50w阿里P8亲自下场,教你如何从测试进阶
Greenplum6.x-版本变化记录-常用手册
Analysis of abnormal channel number information before and after AGC re signature service
Platformization, a fulcrum of strong chain complementing chain
Qt Charts使用(重写QChartView,实现一些自定义功能)