当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- 【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
- [in depth learning series (8)]: principles of transform and actual combat
- Prompt 范式简述
- 业务架构图
- Thesis tips
- Replace convolution with full connection layer -- repmlp
- One book 1078: sum of fractional sequences
- 【雙目視覺】雙目矯正
- 图像增强的几个方法以及Matlab代码
- Yolov3 trains its own data set (mmdetection)
猜你喜欢
Open3D学习笔记一【初窥门径,文件读取】
Installation and use of image data crawling tool Image Downloader
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
Sorting out dialectics of nature
将恶意软件嵌入到神经网络中
How do vision transformer work? [interpretation of the paper]
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
Win10+vs2017+denseflow compilation
Implementation of yolov5 single image detection based on pytorch
联邦学习下的数据逆向攻击 -- GradInversion
随机推荐
Hystrix dashboard cannot find hystrix Stream solution
【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
What if the notebook computer cannot run the CMD command
【Cascade FPD】《Deep Convolutional Network Cascade for Facial Point Detection》
CONDA common commands
業務架構圖
【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
【双目视觉】双目矫正
Programmers can only be 35? The 74 year old programmer in the United States has been programming for 57 years and has not retired
Thesis tips
【学习笔记】Matlab自编图像卷积函数
Handwritten call, apply, bind
Summary of open3d environment errors
The internal network of the server can be accessed, but the external network cannot be accessed
【Batch】learning notes
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
How do vision transformer work? [interpretation of the paper]
open3d学习笔记四【表面重建】
用MLP代替掉Self-Attention
【MobileNet V3】《Searching for MobileNetV3》