当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
用于类别增量学习的动态可扩展表征 -- DER
【Batch】learning notes
jetson nano安装tensorflow踩坑记录(scipy1.4.1)
【学习笔记】反向误差传播之数值微分
Using transformer for object detection and semantic segmentation
Graph Pooling 简析
Simply test the two different data transmission methods of content length and chunked
简易打包工具的安装与使用
open3d学习笔记四【表面重建】
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
随机推荐
Get the width and height of the screen in real time (adaptive)
On the confrontation samples and their generation methods in deep learning
Wang extracurricular words
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
多站点高可用部署
Principes fondamentaux de la théorie musicale (brève introduction)
针对语义分割的真实世界的对抗样本攻击
OpenCV 6.4 中值滤波器的使用
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
[learning notes] numerical differentiation of back error propagation
How to back up the configuration before the idea when reinstalling the idea
Global and Chinese market of snow sweepers 2022-2028: Research Report on technology, participants, trends, market size and share
Vscode下中文乱码问题
Media query usage
Using super ball embedding to enhance confrontation training
Target detection for long tail distribution -- balanced group softmax
JVM instructions
open3d环境错误汇总
AR system summary harvest
力扣方法总结:双指针