当前位置:网站首页>最长等比子序列
最长等比子序列
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;
}
边栏推荐
- How to turn on night mode on laptop
- 论文写作tip2
- What if the notebook computer cannot run the CMD command
- (15) Flick custom source
- 【学习笔记】Matlab自编图像卷积函数
- Timeout docking video generation
- What if a new window always pops up when opening a folder on a laptop
- 半监督之mixmatch
- 利用超球嵌入来增强对抗训练
- Summary of open3d environment errors
猜你喜欢

Replace convolution with full connection layer -- repmlp

浅谈深度学习中的对抗样本及其生成方法
![[binocular vision] binocular stereo matching](/img/93/2e916038f0e7d0c7b3bf64f8dc1b4e.png)
[binocular vision] binocular stereo matching

Win10+vs2017+denseflow compilation

Command line is too long

Embedding malware into neural networks

【Sparse-to-Dense】《Sparse-to-Dense:Depth Prediction from Sparse Depth Samples and a Single Image》

用MLP代替掉Self-Attention

【Batch】learning notes

用于类别增量学习的动态可扩展表征 -- DER
随机推荐
Look for we media materials from four aspects to ensure your creative inspiration
EKLAVYA -- 利用神经网络推断二进制文件中函数的参数
CONDA common commands
Replace convolution with full connection layer -- repmlp
C # connect to MySQL database
浅谈深度学习模型中的后门
半监督之mixmatch
label propagation 标签传播
Eklavya -- infer the parameters of functions in binary files using neural network
Execution of procedures
Sorting out dialectics of nature
程序的执行
[CVPR‘22 Oral2] TAN: Temporal Alignment Networks for Long-term Video
Open3d learning note 5 [rgbd fusion]
The internal network of the server can be accessed, but the external network cannot be accessed
论文tips
Memory model of program
[C # note] the data in DataGridView saved in WinForm is excel and CSV
Label propagation
ABM thesis translation