当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- E-R draw clear content
- [Sparse to Dense] Sparse to Dense: Depth Prediction from Sparse Depth samples and a Single Image
- Organigramme des activités
- Common CNN network innovations
- 【Programming】
- 包图画法注意规范
- 【Random Erasing】《Random Erasing Data Augmentation》
- ABM thesis translation
- How to turn on night mode on laptop
- Income in the first month of naked resignation
猜你喜欢
I'll show you why you don't need to log in every time you use Taobao, jd.com, etc?
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
【双目视觉】双目矫正
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
TimeCLR: A self-supervised contrastive learning framework for univariate time series representation
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
针对tqdm和print的顺序问题
程序的执行
open3d学习笔记四【表面重建】
The internal network of the server can be accessed, but the external network cannot be accessed
随机推荐
用MLP代替掉Self-Attention
【Batch】learning notes
解决jetson nano安装onnx错误(ERROR: Failed building wheel for onnx)总结
Common CNN network innovations
浅谈深度学习中的对抗样本及其生成方法
Implementation of yolov5 single image detection based on pytorch
open3d学习笔记五【RGBD融合】
利用超球嵌入来增强对抗训练
Installation and use of image data crawling tool Image Downloader
Correction binoculaire
[C # note] the data in DataGridView saved in WinForm is excel and CSV
Target detection for long tail distribution -- balanced group softmax
Open3d learning note 5 [rgbd fusion]
Open3d learning notes II [file reading and writing]
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
Common machine learning related evaluation indicators
Replace self attention with MLP
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
Feature Engineering: summary of common feature transformation methods