当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- What if a new window always pops up when opening a folder on a laptop
- Jetson nano installation tensorflow stepping pit record (scipy1.4.1)
- 【学习笔记】反向误差传播之数值微分
- Open3d learning note 3 [sampling and voxelization]
- 用于类别增量学习的动态可扩展表征 -- DER
- C#与MySQL数据库连接
- Open3d learning notes II [file reading and writing]
- [binocular vision] binocular correction
- 【Batch】learning notes
- Memory model of program
猜你喜欢

Proof and understanding of pointnet principle

用于类别增量学习的动态可扩展表征 -- DER

【Random Erasing】《Random Erasing Data Augmentation》

Remplacer l'auto - attention par MLP

Execution of procedures

【Programming】

Label propagation
![Open3d learning notes 1 [first glimpse, file reading]](/img/68/68ea87817dbf788591216a32c9375b.png)
Open3d learning notes 1 [first glimpse, file reading]

【Cutout】《Improved Regularization of Convolutional Neural Networks with Cutout》

Where do you find the materials for those articles that have read 10000?
随机推荐
业务架构图
Correction binoculaire
【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》
【雙目視覺】雙目矯正
[binocular vision] binocular correction
服务器的内网可以访问,外网却不能访问的问题
How gensim freezes some word vectors for incremental training
Hystrix dashboard cannot find hystrix Stream solution
Common CNN network innovations
CVPR19-Deep Stacked Hierarchical Multi-patch Network for Image Deblurring论文复现
【BiSeNet】《BiSeNet:Bilateral Segmentation Network for Real-time Semantic Segmentation》
Traditional target detection notes 1__ Viola Jones
Open3d learning note 5 [rgbd fusion]
open3d学习笔记四【表面重建】
Command line is too long
【双目视觉】双目矫正
Yolov3 trains its own data set (mmdetection)
【DIoU】《Distance-IoU Loss:Faster and Better Learning for Bounding Box Regression》
【Batch】learning notes
AR系统总结收获