当前位置:网站首页>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
边栏推荐
- 快速集成认证服务-HarmonyOS平台
- Greenplum6.x常用语句
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- [wechat applet: cache operation]
- 23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
- Markdown编辑器Editor.md插件的使用
- Count sort (diagram)
- Required String parameter ‘XXX‘ is not present
- Arm GIC (IV) GIC V3 register class analysis notes.
- 测试踩坑 - 当已有接口(或数据库表中)新增字段时,都需要注意哪些测试点?
猜你喜欢
Arm GIC (IV) GIC V3 register class analysis notes.
IP地址的类别
What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
let const
Rapid integration of authentication services - harmonyos platform
[step on the pit] Nacos registration has been connected to localhost:8848, no available server
数据分片介绍
Greenplum6.x搭建_环境配置
Compilation and linking of programs
指针进阶,字符串函数
随机推荐
How to integrate app linking services in harmonyos applications
Greenplum6.x重新初始化
Greenplum6.x监控软件搭建
Greenplum6.x-版本变化记录-常用手册
Rapid integration of authentication services - harmonyos platform
Nanjing commercial housing sales enabled electronic contracts, and Junzi sign assisted in the online signing and filing of housing transactions
Three usage scenarios of annotation @configurationproperties
Componentspace2022, assertions, protocols, bindings, and configuration files
Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error
JS的操作
【MySQL】数据库进阶之触发器内容详解
Greenplum6.x搭建_安装
快速集成认证服务-HarmonyOS平台
Greenplum 6.x version change record common manual
指针进阶,字符串函数
Database storage - table partition
NCS Chengdu New Electric interview Experience
更改当前文件夹及文件夹下文件日期shell脚本
关于基于kangle和EP面板使用CDN
QT charts use (rewrite qchartview to realize some custom functions)