当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- 【MnasNet】《MnasNet:Platform-Aware Neural Architecture Search for Mobile》
- C # connect to MySQL database
- jetson nano安装tensorflow踩坑记录(scipy1.4.1)
- Apple added the first iPad with lightning interface to the list of retro products
- 【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》
- Timeout docking video generation
- Latex formula normal and italic
- 【MobileNet V3】《Searching for MobileNetV3》
- WCF更新服务引用报错的原因之一
- 【Mixup】《Mixup:Beyond Empirical Risk Minimization》
猜你喜欢

Semi supervised mixpatch

Common CNN network innovations

利用Transformer来进行目标检测和语义分割

open3d学习笔记五【RGBD融合】

Pointnet understanding (step 4 of pointnet Implementation)

联邦学习下的数据逆向攻击 -- GradInversion

浅谈深度学习模型中的后门

【Hide-and-Seek】《Hide-and-Seek: A Data Augmentation Technique for Weakly-Supervised Localization xxx》

【Mixup】《Mixup:Beyond Empirical Risk Minimization》

Traditional target detection notes 1__ Viola Jones
随机推荐
Pointnet understanding (step 4 of pointnet Implementation)
Mmdetection trains its own data set -- export coco format of cvat annotation file and related operations
Prompt 范式简述
CPU的寄存器
利用Transformer来进行目标检测和语义分割
Translation of the paper "written mathematical expression recognition with bidirectionally trained transformer"
Latex formula normal and italic
【AutoAugment】《AutoAugment:Learning Augmentation Policies from Data》
针对tqdm和print的顺序问题
[mixup] mixup: Beyond Imperial Risk Minimization
[multimodal] clip model
[in depth learning series (8)]: principles of transform and actual combat
What if the laptop can't search the wireless network signal
Apple added the first iPad with lightning interface to the list of retro products
open3d学习笔记三【采样与体素化】
In the era of short video, how to ensure that works are more popular?
What if the notebook computer cannot run the CMD command
Remplacer l'auto - attention par MLP
【Mixup】《Mixup:Beyond Empirical Risk Minimization》
Hystrix dashboard cannot find hystrix Stream solution