当前位置:网站首页>Longest isometric subsequence
Longest isometric subsequence
2022-07-02 08:07:00 【programmercherry】
#include <iostream>
using namespace std;
#include <vector>
#include <unordered_map>
/* Longest isometric subsequence */
int longestArithSeqLength(vector<int>& A) {
if (A.size() == 2) {
return 2;
}
if (A.size() == 3) {
return A[2] / A[1] == A[1] / A[0];
}
int n = A.size();
vector<vector<int>> dp(n, vector<int>(n, 2));
unordered_map<int, vector<int>> cntHashMap;
for (int i = 0; i < n; ++i) {
cntHashMap[A[i]].emplace_back(i);
}
int res = 2;
for (int i = 1; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (cntHashMap.count(A[i] * A[i] / A[j])) {
for (const auto m : cntHashMap[A[i] * A[i] / A[j]]) {
if (m < i) {
dp[i][j] = max(dp[i][j], dp[m][i] + 1);
}
else {
break;
}
}
res = max(res, dp[i][j]);
}
}
}
return res;
}
int main() {
/*vector<int> A = { 1, 3, 2, 5, 4 };*/
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
cout << longestArithSeqLength(A) << endl;
return 0;
}
边栏推荐
- 深入理解JVM
- 力扣每日一题刷题总结:链表篇(持续更新)
- Global and Chinese markets for conventional rubber track 2022-2028: Research Report on technology, participants, trends, market size and share
- 力扣每日一题刷题总结:二叉树篇(持续更新)
- What if the laptop can't search the wireless network signal
- 多站点高可用部署
- Carsim-路面3D形状文件参数介绍
- Brief introduction of prompt paradigm
- Matlab数学建模工具
- On the back door of deep learning model
猜你喜欢

On the back door of deep learning model

SQLyog远程连接centos7系统下的MySQL数据库

Income in the first month of naked resignation

【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》

针对tqdm和print的顺序问题

I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?

Replace self attention with MLP

【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》

Where do you find the materials for those articles that have read 10000?

【MagNet】《Progressive Semantic Segmentation》
随机推荐
Replace self attention with MLP
[C # note] the data in DataGridView saved in WinForm is excel and CSV
力扣每日一题刷题总结:字符串篇(持续更新)
Look for we media materials from four aspects to ensure your creative inspiration
Using super ball embedding to enhance confrontation training
Summary of open3d environment errors
OpenCV关于x,y坐标容易混淆的心得
Carsim-路面3D形状文件参数介绍
浅谈深度学习模型中的后门
Find and rfind methods in string
SQLyog远程连接centos7系统下的MySQL数据库
Wang extracurricular words
Nacos service registration in the interface
Open3D学习笔记一【初窥门径,文件读取】
Using transformer for object detection and semantic segmentation
【学习笔记】Matlab自编图像卷积函数
(15) Flick custom source
【MagNet】《Progressive Semantic Segmentation》
我的vim配置文件
【雙目視覺】雙目矯正