当前位置:网站首页>Dynamic programming -- linear DP
Dynamic programming -- linear DP
2022-07-06 00:42:00 【Lin Shiliu should work hard】
1. Longest ascending subsequence (LIS)
Plain writing n^2
for(int i=1;i<=n;i++)
{
f[i]=1;
for(int j=1;j<i;j++)
if(a[i]>a[j])
f[i]=max(f[i],f[j]+1);
}
int m=0;
for(int i=1;i<=n;i++) m=max(m,f[i]);
Binary optimization nlogn
int f[N];// The length is i The last bit of the increasing subsequence of
int LIS()
{
int len=0;
f[0]=-0x3f3f3f3f;
for(int i=1;i<=n;i++)
{
int l=0,r=len;
while(l<r)// Find less than a[i] The last number of
{
int mid=l+r+1>>1;
if(f[mid]<a[i])
l=mid;
else
r=mid-1;
}
len=max(len,r+1);
f[r+1]=a[i];
}
return len;
}
2. Longest common subsequence (LCS)
//LCS o(n^2)
int f[N][N];// Before the first sequence i Letters and the first of the second sequence j A subsequence of letters Maximum common subsequence length of
边栏推荐
- LeetCode 斐波那契序列
- FFmpeg抓取RTSP图像进行图像分析
- [Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
- 孤勇者
- Room cannot create an SQLite connection to verify the queries
- Novice entry depth learning | 3-6: optimizer optimizers
- Go learning --- read INI file
- Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
- 猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
- Cloud guide DNS, knowledge popularization and classroom notes
猜你喜欢
esxi的安装和使用
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
Set data real-time update during MDK debug
Extracting profile data from profile measurement
XML配置文件
Extension and application of timestamp
MCU realizes OTA online upgrade process through UART
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
AtCoder Beginner Contest 254【VP记录】
Free chat robot API
随机推荐
LeetCode 1598. Folder operation log collector
How to use the flutter framework to develop and run small programs
Introduction of motor
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
MCU realizes OTA online upgrade process through UART
Go learning --- structure to map[string]interface{}
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
Why can't mathematics give machine consciousness
数据分析思维分析方法和业务知识——分析方法(二)
MCU通过UART实现OTA在线升级流程
Intranet Security Learning (V) -- domain horizontal: SPN & RDP & Cobalt strike
MySQL storage engine
curlpost-php
AtCoder Beginner Contest 254【VP记录】
notepad++正则表达式替换字符串
电机的简介
LeetCode 6005. The minimum operand to make an array an alternating array
云导DNS和知识科普以及课堂笔记
STM32 key chattering elimination - entry state machine thinking
Spark SQL空值Null,NaN判断和处理