当前位置:网站首页>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
边栏推荐
- POJ - 3616 Milking Time(DP+LIS)
- selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
- [Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
- JS operation
- 南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
- Interpolation lookup (two methods)
- [Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
- Compilation and linking of programs
- LeetCode 715. Range 模块
- How to add a mask of a target in a picture
猜你喜欢
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
NCS Chengdu Xindian interview experience
MySQL主从延迟的解决方案
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
关于基于kangle和EP面板使用CDN
oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
let const
Data type - integer (C language)
Greenplum 6.x reinitialization
Three series of BOM elements
随机推荐
How to integrate app linking services in harmonyos applications
FPGA knowledge accumulation [6]
JS的操作
更改当前文件夹及文件夹下文件日期shell脚本
[wechat applet: cache operation]
Explain Huawei's application market in detail, and gradually reduce 32-bit package applications and strategies in 2022
Greenplum 6.x build_ Environment configuration
[Nanjing University] - [software analysis] course learning notes (I) -introduction
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
Tips for using jeditabletable
实现自定义内存分配器
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
Greenplum6.x重新初始化
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
调用华为游戏多媒体服务的创建引擎接口返回错误码1002,错误信息:the params is error
National SMS center number inquiry
求有符号数的原码、反码和补码【C语言】
LeetCode 715. Range 模块
You should use Google related products with caution
Redis fault handling "can't save in background: fork: cannot allocate memory“