当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- Network metering - transport layer
- open3d学习笔记二【文件读写】
- CPU register
- Installation and use of image data crawling tool Image Downloader
- How to turn on night mode on laptop
- Execution of procedures
- [learning notes] matlab self compiled Gaussian smoother +sobel operator derivation
- 【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
- Ppt skills
- [in depth learning series (8)]: principles of transform and actual combat
猜你喜欢

Network metering - transport layer

服务器的内网可以访问,外网却不能访问的问题

用全连接层替代掉卷积 -- RepMLP
![[learning notes] numerical differentiation of back error propagation](/img/1c/e28e31d7cc5ccc38607c7839ccc5f0.png)
[learning notes] numerical differentiation of back error propagation

【Mixup】《Mixup:Beyond Empirical Risk Minimization》

半监督之mixmatch

应对长尾分布的目标检测 -- Balanced Group Softmax

Specification for package drawing
![[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video](/img/bc/c54f1f12867dc22592cadd5a43df60.png)
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video

Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"
随机推荐
open3d学习笔记二【文件读写】
Organigramme des activités
(15) Flick custom source
Correction binoculaire
open3d学习笔记三【采样与体素化】
w10升级至W11系统,黑屏但鼠标与桌面快捷方式能用,如何解决
The hystrix dashboard reported an error hystrix Stream is not in the allowed list of proxy host names solution
【FastDepth】《FastDepth:Fast Monocular Depth Estimation on Embedded Systems》
Label propagation
【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》
Meta Learning 简述
【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
针对语义分割的真实世界的对抗样本攻击
Hystrix dashboard cannot find hystrix Stream solution
Traditional target detection notes 1__ Viola Jones
解决jetson nano安装onnx错误(ERROR: Failed building wheel for onnx)总结
【MagNet】《Progressive Semantic Segmentation》
latex公式正体和斜体
Open3d learning notes II [file reading and writing]
CONDA common commands