当前位置:网站首页>最长等比子序列
最长等比子序列
2022-07-02 06:27:00 【programmercherry】
#include <iostream>
using namespace std;
#include <vector>
#include <unordered_map>
/* 最长等比子序列 */
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;
}
边栏推荐
- Open3d learning notes 1 [first glimpse, file reading]
- Common CNN network innovations
- 【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
- Prompt 范式简述
- 【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
- 【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
- Common machine learning related evaluation indicators
- 【Mixup】《Mixup:Beyond Empirical Risk Minimization》
- 【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
- Hystrix dashboard cannot find hystrix Stream solution
猜你喜欢

用MLP代替掉Self-Attention

【学习笔记】反向误差传播之数值微分

程序的内存模型

How to turn on night mode on laptop

Network metering - transport layer

【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
![How do vision transformer work? [interpretation of the paper]](/img/93/5f967b876fbd63c07b8cfe8dd17263.png)
How do vision transformer work? [interpretation of the paper]

Eklavya -- infer the parameters of functions in binary files using neural network

【Batch】learning notes

利用Transformer来进行目标检测和语义分割
随机推荐
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
[multimodal] clip model
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
In the era of short video, how to ensure that works are more popular?
EKLAVYA -- 利用神经网络推断二进制文件中函数的参数
E-R draw clear content
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
Installation and use of image data crawling tool Image Downloader
利用Transformer来进行目标检测和语义分割
How to clean up logs on notebook computers to improve the response speed of web pages
Open3d learning note 3 [sampling and voxelization]
应对长尾分布的目标检测 -- Balanced Group Softmax
【Wing Loss】《Wing Loss for Robust Facial Landmark Localisation with Convolutional Neural Networks》
【Random Erasing】《Random Erasing Data Augmentation》
包图画法注意规范
ABM thesis translation
Graph Pooling 简析
【双目视觉】双目矫正
CPU的寄存器
open3d学习笔记二【文件读写】